UNPKG

gnablib

Version:

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

2 lines 977 B
/*! Copyright 2024-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 XorShift128 extends e{constructor(){super(...arguments),this.bitGen=32,this.safeBits=32}trueSave(){const s=new Uint8Array(this._state.slice().buffer);return t.i32(s,0,4),s}rawNext(){const t=this._state[0]^this._state[0]<<11;return this._state[0]=this._state[1],this._state[1]=this._state[2],this._state[2]=this._state[3],this._state[3]=this._state[3]^this._state[3]>>>19^t^t>>>8,this._state[3]>>>0}get[Symbol.toStringTag](){return"xorshift128"}static new(t=!1){return new XorShift128(Uint32Array.of(123456789,362436069,521288629,88675123),t)}static seed(t,s,e,r,i=!1){const a=Uint32Array.of(t,s,e,r);return new XorShift128(a,i)}static restore(e,r=!1){s("state",e).exactly(16).throwNot();const i=e.slice();t.i32(i,0,4);const a=new Uint32Array(i.buffer);return new XorShift128(a,r)}}