gnablib
Version:
A lean, zero dependency library to provide a useful base for your project.
2 lines • 688 B
JavaScript
/*! Copyright 2024-2025 the gnablib contributors MPL-1.1 */
import{sLen as t,sNum as s}from"../safe/safe.js";import{APrng32 as r}from"./APrng32.js";export class Marsaglia extends r{constructor(){super(...arguments),this.bitGen=4,this.safeBits=3}trueSave(){return this._state.slice()}rawNext(){const t=this._state[0]%10,s=this._state[0]/10|0;return this._state[0]=s+6*t,this._state[0]%10}get[Symbol.toStringTag](){return"marsaglia"}static new(t=!1){return new Marsaglia(Uint8Array.of(23),t)}static seed(t,r=!1){return s("seed",t).natural().atMost(99).throwNot(),new Marsaglia(Uint8Array.of(t),r)}static restore(s,r=!1){return t("state",s).exactly(1).throwNot(),new Marsaglia(s.slice(),r)}}