A fast, seedable pseudo-random number generator, using WebAssembly and SIMD instructions.
⚠️ This is not a cryptographically secure PRNG. Do NOT rely on it for security ⚠️
Usage in Node:
import { createPrng } from "simd-prng";
// Basic usage
const prng = createPrng();
console.log(prng.randomInt());
// Custom seed
const seed = new Uint32Array([47346587, 98347504]);
const seeded = createPrng(seed);
console.log(prng.randomInt()); // 652389222
// A single integer is also valid as seed
const seeded = createPrng(seed[0]);
console.log(prng.randomInt()); // 2962608483
Usage in browsers:
// Vite integration
import { init } from "simd-prng/vite";
// library needs to be asynchronously initialized first
const createPrng = await init();
const prng = createPrng();
console.log(prng.randomInt());
Usage when ESM imports of WebAssembly are available:
import { createPrng } from "simd-prng/wasm";
const prng = createPrng();
console.log(prng.randomInt());
This library is a straight WebAssembly port of SIMD-oriented Fast Mersenne Twister (SFMT), using Emscripten. The original implementation was designed to leverage SIMD instructions for speed. This port preserves that property using WebAssembly SIMD.
The original C source code is licensed under BSD-3-Clause, so we retain it for the rest of the library.