UNPKG

gnablib

Version:

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

2 lines 839 B
/*! Copyright 2024-2025 the gnablib contributors MPL-1.1 */ import{asLE as t}from"../endian/platform.js";import{U64Mut as r}from"../primitive/number/U64.js";import{sLen as s}from"../safe/safe.js";import{APrng64 as e}from"./APrng64.js";export class XorShift64 extends e{constructor(){super(...arguments),this.bitGen=64,this.safeBits=64}rawNext(){return this._state.xorEq(this._state.lShift(13)),this._state.xorEq(this._state.rShift(7)),this._state.xorEq(this._state.lShift(17)),this._state.clone()}get[Symbol.toStringTag](){return"xorshift64"}static new(t=!1){const s=r.fromI32s(3418323524,20529293);return new XorShift64(s,t)}static seed(t,r=!1){return new XorShift64(t.mut(),r)}static restore(e,i=!1){s("state",e).exactly(8).throwNot();const o=e.slice();t.i32(o,0,2);const n=new Uint32Array(o.buffer);return new XorShift64(r.mount(n),i)}}