simd-prng
v0.2.2
Published
A fast PRNG based on SIMD instructions
Maintainers
Readme
simd-prng
A fast, seedable pseudo-random number generator, using WebAssembly and SIMD instructions.
Example
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()); // 2962608483Usage 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());Details
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.
License
The original C source code is licensed under BSD-3-Clause, so we retain it for the rest of the library.
