Created
September 4, 2012 01:25
-
-
Save ericraio/3615573 to your computer and use it in GitHub Desktop.
This file contains 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
// Secure random hex in js like SecureRandom.hex in ruby | |
function secureRandom(n){ | |
n = n+1 || 17; | |
var str = []; | |
while (--n) { | |
var r = Math.floor(Math.random()*256) | |
.toString(16) | |
.substr(Math.floor(Math.random()*2),1) | |
|| String.fromCharCode(65+(Math.floor(Math.random()*8))); | |
str.push(r); | |
} | |
return str.join(''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment