-
-
Save gregorynicholas/3453424 to your computer and use it in GitHub Desktop.
[JS] - generateRandomKey
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
function generateRandomKey(size) | |
{ | |
var keyset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$.+-_$'; | |
var result = []; | |
for (var i = 0; i < size; i++) { | |
// todo: Math.random has issues and baggage: http://stackoverflow.com/questions/424292/how-to-create-my-own-javascript-random-number-generator-that-i-can-also-set-the | |
var rnum = Math.floor(Math.random() * keyset.length); | |
result[i] = keyset.substring(rnum, rnum + 1); | |
} | |
return result.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment