I would either extract the random number generator into an extra method, or simply use new Random().nextInt(36) from package java.util to generate a random integer between 0 and 35 (both inclusive).. You could also make the method more generic by adding boundary parameters (min, max). If we want regex matches non-alphanumeric characters, prefix it with a negate symbol ^, meaning we want any characters that are not alphanumeric. 1. How to set the default value for an HTML