Skip to content

Instantly share code, notes, and snippets.

@darrenmothersele
Created November 2, 2017 09:34
Show Gist options
  • Select an option

  • Save darrenmothersele/7cd24da0f35d450babd4745c7f208acf to your computer and use it in GitHub Desktop.

Select an option

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);
@YoungseokCh
Copy link

This is exactly what I wanted!

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