Created
June 15, 2010 20:09
-
-
Save eric1234/439654 to your computer and use it in GitHub Desktop.
Random string generator
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
| Array.prototype.random = function() { | |
| return this[parseInt(Math.random() * this.length)]; | |
| } | |
| String.random = function(len) { | |
| var chars = $R('a', 'z').toArray().concat($R('A', 'Z').toArray()); | |
| return $R(1, len).inject('', function(m, i) {return m + chars.random()}); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ideal for generating random passwords. Just call:
String.random(8)