gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 832 B
JavaScript
/*! Copyright 2024-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 e}from"./APrng32.js";export class XorShift32 extends e{constructor(){super(...arguments),this.bitGen=32,this.safeBits=32}trueSave(){const r=new Uint8Array(this._state.slice().buffer);return t.i32(r,0,1),r}rawNext(){return this._state[0]^=this._state[0]<<13,this._state[0]^=this._state[0]>>>17,this._state[0]^=this._state[0]<<5,this._state[0]}get[Symbol.toStringTag](){return"xorshift32"}static new(t=!1){return new XorShift32(Uint32Array.of(2463534242),t)}static seed(t,r=!1){return new XorShift32(Uint32Array.of(t),r)}static restore(e,s=!1){r("state",e).exactly(4).throwNot();const i=e.slice();t.i32(i,0,1);const a=new Uint32Array(i.buffer);return new XorShift32(a,s)}}