Skip to content

Instantly share code, notes, and snippets.

@mike-neck
Created November 5, 2011 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-neck/1341399 to your computer and use it in GitHub Desktop.
Save mike-neck/1341399 to your computer and use it in GitHub Desktop.
6 - 14 桁のパスワードを発行するスクリプト (少し @fumokmm さんのコードを拝借している) written by @mike_neck https://gist.github.com/1341399 #gdk48 #jggugcamp
/**
* This code is written by @fumokmm
* {@see http://d.hatena.ne.jp/fumokmm/20090420/1240202410}
*/
IntRange.metaClass.define {
random{
int from = delegate.isReverse()? to : from
int to = delegate.isReverse()? from : to
int size = to - from + 1
(Math.floor(Math.random() * size) + from) as int
}
}
/**
* Here is my code.
*/
enum RandomChar{
LOWER_CASE{
char getChar(){
((int)'a') + (0..25).random()
}
}, UPPER_CASE{
char getChar(){
((int)'A') + (0..25).random()
}
}, NUMERO_CASE{
char getChar(){
((int)'0') + (0..9).random()
}
};
static final List<RandomChar> items = new ArrayList(EnumSet.allOf(RandomChar.class));
public static char get(){
items.get(new IntRange(0, items.size() - 1).random()).getChar()
}
}
def getPassword = {
password = ''
(6..14).random().times{
password += RandomChar.get()
}
password
}
getPassword()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment