Created
September 22, 2022 17:43
-
-
Save kigiri/5972d0761be4905d099aa64fbcabf1ac to your computer and use it in GitHub Desktop.
seeded random in 385bytes of js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomSeed = ((r,a,n)=>(d,o,m,i,z,e,x)=>(o=n(3941471299,d),m=a(0.8633289230056107-(o>>>0)*r),i=a(0.15019597788341343-(o=n(o,d)>>>0)*r),z=a(0.9176952994894236-(o=n(o,d)>>>0)*r),e=1,()=>(x=2091639*m+e*r,m=i,i=z,z=x-(e=x|0))))(23283064365386963e-26,e=>e+(e<0),(e,r)=>{for(let t of r){let r=.02519603282416938*(e+=t.charCodeAt());r-=e=r>>>0,r*=e,r-=e=r>>>0,e+=4294967296*r}return e}) | |
// usage: | |
const rand = randomSeed('hello') // must be a string | |
rand() // use like Math.random() | |
// the end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment