
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
@alisey/pcg32
Advanced tools
A WebAssembly port of the PCG Random Number Generator, Minimal C Edition.
import * as pcg from '@alisey/pcg32';
pcg.setState(0x0123456789ABCDEFn);
console.log(pcg.randomInt(10)); // ⇒ 5
console.log(pcg.random()); // ⇒ 0.3697000732146962
randomInt(bound: number): numberReturns a uniformly distributed 32-bit unsigned random integer in the range
[0, bound), where bound is a number from 1 to 2³².
random(): numberReturns 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): voidUpdates 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(): bigintReturns a 64-bit unsigned BigInt representing the internal state of the generator.
seed(value?: bigint): voidSeeds 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 as
Math.floor(Math.random() * n), but doesn't introduce bias. pcg.random() is
2 times slower than Math.random().
In SpiderMonkey and JavaScriptCore both functions are 10 times slower than native equivalents.
npm installnpm run buildnpm run testnpm run demonpm run perfFAQs
PCG-32 random number generator implemented in WebAssembly
We found that @alisey/pcg32 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.