Created
March 26, 2011 14:38
-
-
Save tyuki39/888331 to your computer and use it in GitHub Desktop.
[0-9a-zA-Z_]からなる16文字のランダム文字列
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new Random と nextIntを使用 | |
[*0..9,*'a'..'z',*'A'..'Z','_'].with{a->println new Random().with{(1..16).collect{a[nextInt(a.size())]}.join()}} | |
// Math.randomを使用 | |
[*0..9,*'a'..'z',*'A'..'Z','_'].with{a->println((1..16).collect{a[(int)Math.random()*a.size()]}.join())} | |
// def と println版 | |
def a=[*0..9,*'a'..'z',*'A'..'Z','_'];println((1..16).collect{a[(int)Math.random()*a.size()]}.join()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最近流行りの展開演算子だっ!