Skip to content

Instantly share code, notes, and snippets.

@demoth
Created November 15, 2013 17:06
Show Gist options
  • Save demoth/7487896 to your computer and use it in GitHub Desktop.
Save demoth/7487896 to your computer and use it in GitHub Desktop.
Simple random string generator. Found on http://stackoverflow.com/a/8138604/1928171 by tim_yates
def generator = { String alphabet, int n ->
new Random().with {
(1..n).collect { alphabet[nextInt(alphabet.length())] }.join('')
}
}
def alphabet = (('А'..'Я') + ('а'..'я') + ('0'..'9')).join('')
println generator(alphabet, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment