Initialize an array containing all the accepted chars (CHARS_ARRAY
), then instantiate a SecureRandom instance, and call nextInt(CHARS_ARRAY.length)
repeatedly to get a random index in your char array. Append each char to a StringBuilder
until you get the expected number of chars.