UNPKG

gnablib

Version:

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

2 lines 830 B
/*! Copyright 2024 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 Mulberry32 extends e{constructor(){super(...arguments),this.bitGen=32,this.safeBits=32}trueSave(){const r=this._state.slice(),e=new Uint8Array(r.buffer);return t.i32(e,0,1),e}rawNext(){this._state[0]+=1831565813;let t=this._state[0];return t=Math.imul(t^t>>>15,1|t),t^=t+Math.imul(t^t>>>7,61|t),(t^t>>>14)>>>0}get[Symbol.toStringTag](){return"mulberry32"}static new(t=!1){return new Mulberry32(Uint32Array.of(0),t)}static seed(t,r=!1){const e=Uint32Array.of(t);return new Mulberry32(e,r)}static restore(e,s=!1){r("state",e).exactly(4).throwNot();const n=e.slice();t.i32(n,0,1);const i=new Uint32Array(n.buffer);return new Mulberry32(i,s)}}