Using Groovy, I\'d like to generate a random sequence of characters from a given regular expression.
[A-Z0-9]
This code is pure Groovy I found on the web:
def key
def giveMeKey(){
String alphabet = (('A'..'N')+('P'..'Z')+('a'..'k')+('m'..'z')+('2'..'9')).join()
def length = 6
key = new Random().with {
(1..length).collect { alphabet[ nextInt( alphabet.length() ) ] }.join()
}
return key
}
The return string is good enough for local use:
BFx9PU
MkbRaE
FKvupt
gEwjby
Gk2kK6
uJmzLB
WRJGKL
RnSUQT