Вы можете использовать библиотеку Apache для этого: RandomStringUtils
RandomStringUtils.randomAlphanumeric(20).toUpperCase();