Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created November 2, 2017 09:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darrenmothersele/7cd24da0f35d450babd4745c7f208acf to your computer and use it in GitHub Desktop.
Save darrenmothersele/7cd24da0f35d450babd4745c7f208acf to your computer and use it in GitHub Desktop.
const validChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let array = new Uint8Array(40);
window.crypto.getRandomValues(array);
array = array.map(x => validChars.charCodeAt(x % validChars.length));
const randomState = String.fromCharCode.apply(null, array);
console.log(randomState);
@3-24
Copy link

3-24 commented May 23, 2018

This is exactly what I wanted!

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