Skip to content

Instantly share code, notes, and snippets.

@jimmywarting
Last active July 27, 2017 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmywarting/919c22f20e1fc9c8b677596b3deabc9c to your computer and use it in GitHub Desktop.
Save jimmywarting/919c22f20e1fc9c8b677596b3deabc9c to your computer and use it in GitHub Desktop.
Tiny fast 314 bytes es6 PRNG
// based on this https://github.com/davidbau/seedrandom#other-fast-prng-algorithms but without `next()`
(b,c,d,f,g,h,k,s=1,t=4022871197)=>(k=u=>{for(d of u)t+=d.charCodeAt(0),f=.02519603282416938*t,t=f>>>0,f-=t,f*=t,t=f>>>0,f-=t,t+=4294967296*f;return 2.3283064365386963e-10*(t>>>0)},c=k(' '),g=k(' '),h=k(' '),c-=k(b),0>c&&(c+=1),g-=k(b),0>g&&(g+=1),h-=k(b),0>h&&(h+=1),b=2091639*c+2.3283064365386963e-10*s,h=b-(0|b))
// usage
// const randomizer = <code>
// const seed = '2' // must be string
// randomizer(seed); // 0.4575677579268813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment