Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate a random 32 bit unsigned integer
function randomUint32() {
if (window && window.crypto && window.crypto.getRandomValues && Uint32Array) {
var o = new Uint32Array(1);
return o[0];
} else {
console.warn('Falling back to pseudo-random client seed');
return Math.floor(Math.random() * Math.pow(2, 32));
Copy link

bryc commented Jan 15, 2019

Some one-liners:

// crypto
window.crypto.getRandomValues(new Uint32Array(1))[0];
// Math.random

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment