Created
July 31, 2015 14:48
-
-
Save RHavar/a6511dea4d4c41aeb1eb to your computer and use it in GitHub Desktop.
Generate a random 32 bit unsigned integer
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 randomUint32() { | |
if (window && window.crypto && window.crypto.getRandomValues && Uint32Array) { | |
var o = new Uint32Array(1); | |
window.crypto.getRandomValues(o); | |
return o[0]; | |
} else { | |
console.warn('Falling back to pseudo-random client seed'); | |
return Math.floor(Math.random() * Math.pow(2, 32)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some one-liners: