UNPKG

gnablib

Version:

A lean, zero dependency library to provide a useful base for your project.

2 lines 1.28 kB
/*! Copyright 2025 the gnablib contributors MPL-1.1 */ import{asLE as t}from"../endian/platform.js";import{sLen as r}from"../safe/safe.js";import{APrng32 as s}from"./APrng32.js";export class Well512 extends s{constructor(){super(...arguments),this._ptr=0,this.bitGen=32,this.safeBits=32}trueSave(){const r=new Uint8Array(65),s=new Uint8Array(this._state.buffer);return r.set(s),t.i32(r,0,16),r[64]=this._ptr,r}rawNext(){let t=this._state[this._ptr],r=this._state[this._ptr+13&15];const s=t^t<<16^r^r<<15;r=this._state[this._ptr+9&15],r^=r>>>11,t=this._state[this._ptr]=s^r;const e=t^t<<5&3661901092;return this._ptr=this._ptr+15&15,t=this._state[this._ptr],this._state[this._ptr]=t^s^e^t<<2^s<<18^r<<28,this._state[this._ptr]}get[Symbol.toStringTag](){return"well512"}static new(t=!1){return new Well512(Uint32Array.of(3141592653,589793238,462643383,2795028841,971693993,751058209,749445923,781640628,620899862,803482534,2117067982,1480865132,823066470,938446095,505822317,2535940812),t)}static seed(t,r,s,e,i,n,a,h,o,_,p,l,c,f,u,w,m=!1){return new Well512(Uint32Array.of(t,r,s,e,i,n,a,h,o,_,p,l,c,f,u,w),m)}static restore(s,e=!1){r("state",s).exactly(65).throwNot();const i=s.slice(0,64);t.i32(i,0,16);const n=new Uint32Array(i.buffer),a=new Well512(n,e);return a._ptr=s[64],a}}