public static String generateString ( int length ) { if ( length <= 0 || length > 100 ) { throw new IllegalArgumentException ( "Can't generate random id with length: " + length ) ; } SecureRandom random = new SecureRandom ( ) ; StringBuilder sb = new StringBuilder ( length ) ; for ( int i = 0 ; i < length ; i ++ ) { sb . append ( ELEMENTS . charAt ( random . nextInt ( ELEMENTS . length ( ) ) ) ) ; } return sb . toString ( ) ; }
Generates random string from ELEMENTS set of chars and numbers