Skip to content

Instantly share code, notes, and snippets.

@rndme
Last active July 26, 2016 01:22
Show Gist options
  • Save rndme/11beca97415dd720cc51dfd3a121fc6b to your computer and use it in GitHub Desktop.
Save rndme/11beca97415dd720cc51dfd3a121fc6b to your computer and use it in GitHub Desktop.
a fast clock times a slow clock and uses a factor of the difference to build a un-predictable 36 alphabet string
function nonce(chars){
var b="", round, last;
while(true){
var round= (Date.now() / (performance.now()*1000)).toString(36).split(".").pop().slice(2, -2);
if(round!=last) b+= round;
if(b.length > chars) break;
last=round;
}
return b.slice(-chars);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment