Skip to content

Instantly share code, notes, and snippets.

@rndme
Last active July 26, 2016 07:55
Show Gist options
  • Save rndme/7fb78880ba3a2297bef746283c82ab46 to your computer and use it in GitHub Desktop.
Save rndme/7fb78880ba3a2297bef746283c82ab46 to your computer and use it in GitHub Desktop.
given a seed value "iv" (optional), returns a deterministic string of pseudo-random hex values of length "chars"
function stream(chars, iv){ // requires https://github.com/emn178/js-sha3/
var buff="", i=0;
iv= sha3_512(iv || (Date.now() / (performance.now()*1000)).toString(36) + (chars/Math.random()));
while(buff.length < chars) buff+= iv = sha3_256(++i + iv);
return buff.slice(0, chars);
}
//ex:
// stream(500, "this is not a great iv");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment