gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 1.5 kB
JavaScript
/*! 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 r}from"./APrng32.js";class e extends r{constructor(){super(...arguments),this.bitGen=32,this.safeBits=32}trueSave(){const s=new Uint8Array(this._state.slice().buffer);return t.i32(s,0,2),s}rawNext(){const t=this._gen();return this._state[1]^=this._state[0],this._state[0]=(this._state[0]<<26|this._state[0]>>>6)^this._state[1]^this._state[1]<<9,this._state[1]=this._state[1]<<13|this._state[1]>>>19,t>>>0}}export class Xoroshiro64s extends e{_gen(){return Math.imul(this._state[0],2654435771)}get[Symbol.toStringTag](){return"xoroshiro64*"}static new(t=!1){return new Xoroshiro64s(Uint32Array.of(2065550767,3793791033),t)}static seed(t,s,r=!1){const e=Uint32Array.of(t,s);return new Xoroshiro64s(e,r)}static restore(r,e=!1){s("state",r).exactly(8).throwNot();const o=r.slice();t.i32(o,0,2);const i=new Uint32Array(o.buffer);return new Xoroshiro64s(i,e)}}export class Xoroshiro64ss extends e{_gen(){const t=Math.imul(this._state[0],2654435771);return Math.imul(t<<5|t>>>27,5)}get[Symbol.toStringTag](){return"xoroshiro64**"}static new(t=!1){return new Xoroshiro64ss(Uint32Array.of(2065550767,3793791033),t)}static seed(t,s,r=!1){const e=Uint32Array.of(t,s);return new Xoroshiro64ss(e,r)}static restore(r,e=!1){s("state",r).exactly(8).throwNot();const o=r.slice();t.i32(o,0,2);const i=new Uint32Array(o.buffer);return new Xoroshiro64ss(i,e)}}