Skip to content

Instantly share code, notes, and snippets.

@earthboundkid
Created January 24, 2020 18:57
Show Gist options
  • Save earthboundkid/3c40e4d2d5529e05f65676bb054758d8 to your computer and use it in GitHub Desktop.
Save earthboundkid/3c40e4d2d5529e05f65676bb054758d8 to your computer and use it in GitHub Desktop.
Generate random hex digits
function randomHex(n) {
let bytes = new Uint8Array(n);
crypto.getRandomValues(bytes);
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment