Skip to content

Instantly share code, notes, and snippets.

@shawnlauzon
Created April 24, 2012 18:43
Show Gist options
  • Save shawnlauzon/2482527 to your computer and use it in GitHub Desktop.
Save shawnlauzon/2482527 to your computer and use it in GitHub Desktop.
Generate a password of the given size using any set of characters
int password_length = 12
if (args.size() > 0) {
password_length = args[0] as int
}
String validChars ="qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM"
int maxIndex = validChars.length()
def rnd = new Random()
def password = (1..password_length).sum {
validChars[rnd.nextInt(maxIndex)]
}
println(password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment