PCG-32 random number generator implemented in WebAssembly
A WebAssembly port of the PCG Random Number Generator, Minimal C Edition.
``js
import * as pcg from '@alisey/pcg32';
pcg.setState(0x0123456789ABCDEFn);
console.log(pcg.randomInt(10)); // ⇒ 5
console.log(pcg.random()); // ⇒ 0.3697000732146962
`
##### randomInt(bound: number): number
Returns a uniformly distributed 32-bit unsigned random integer in the range
0, bound), where bound is a number from 1 to 2³².
##### random(): number
Returns a uniformly distributed floating point number in the range [0, 1) that
has been rounded down to the nearest multiple of 2⁻⁵³.
##### setState(state: bigint): void
Updates the internal state of the generator. The generator has 2⁶⁴ possible
internal states, and iterates through all of them. state is a 64-bit unsigned
BigInt.
##### getState(): bigint
Returns a 64-bit unsigned BigInt representing the internal state of the
generator.
##### seed(value?: bigint): void
Seeds the generator with a 64-bit BigInt. If the value is not provided, uses
a value based on Math.random().
As of 2021, in V8 pcg.randomInt() is as fast asMath.floor(Math.random() * n), but doesn't introduce bias. pcg.random() isMath.random()
2 times slower than .
In SpiderMonkey and JavaScriptCore both functions are 10 times slower than
native equivalents.
1. npm installnpm run build
2. npm run test
3. npm run demo
4. npm run perf`
5.