gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 1.01 kB
JavaScript
/*! Copyright 2025 the gnablib contributors MPL-1.1 */
import{asLE as t}from"../endian/platform.js";import{sLen as s}from"../safe/safe.js";import{APrng32 as e}from"./APrng32.js";export class Sfc16 extends e{constructor(){super(...arguments),this.bitGen=16,this.safeBits=16}trueSave(){const s=new Uint8Array(this._state.slice().buffer);return t.i16(s,0,4),s}rawNext(){const t=this._state[0]+this._state[1]+this._state[3];return this._state[3]+=1,this._state[0]=this._state[1]^this._state[1]>>>5,this._state[1]=this._state[2]+(this._state[2]<<3),this._state[2]=(this._state[2]<<5|this._state[2]>>>11)+t,65535&t}get[Symbol.toStringTag](){return"sfc16"}static new(t=!1){return new Sfc16(Uint16Array.of(13030,58465,13184,11),t)}static seed(t,s,e,r,i=!1){const a=Uint16Array.of(t,s,e,1);null!=r&&(a[3]=r);const n=new Sfc16(a,i);for(let t=0;t<10;t++)n.rawNext();return n}static restore(e,r=!1){s("state",e).exactly(8).throwNot();const i=e.slice();t.i16(i,0,3);const a=new Uint16Array(i.buffer);return new Sfc16(a,r)}}