public String randomString ( String permitted , int length ) { StringBuilder result = new StringBuilder ( length ) ; int maxIndex = permitted . length ( ) ; for ( int i = 0 ; i < length ; i ++ ) { int index = random ( maxIndex ) ; char value = permitted . charAt ( index ) ; result . append ( value ) ; } return result . toString ( ) ; }
Creates a random string consisting only of supplied characters .