https://github.com/cristian-5/pcg-random-wasm
PCG PRNG port in webassembly
https://github.com/cristian-5/pcg-random-wasm
pcg-random prng webassembly
Last synced: 5 months ago
JSON representation
PCG PRNG port in webassembly
- Host: GitHub
- URL: https://github.com/cristian-5/pcg-random-wasm
- Owner: cristian-5
- License: other
- Created: 2023-04-06T14:59:27.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-09T18:49:47.000Z (over 1 year ago)
- Last Synced: 2025-09-02T20:46:25.935Z (10 months ago)
- Topics: pcg-random, prng, webassembly
- Language: WebAssembly
- Homepage: http://www.pcg-random.org
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
## pcg-random-wasm
🎲 **Web Assembly PCG** random number generator http://www.pcg-random.org .\
💗 **Handwritten**, **commented** port based on *Ph.D. Melissa E. O'Neill*'s work.
> PCG is a family of simple fast space-efficient statistically good algorithms for random number generation.\
> Unlike many general-purpose RNGs, they are also hard to predict.
This project comes with a `p5.js` sketch to demonstrate uniform distribuition.\
⚠️ **Attention:** the sketch needs to be served by a web server, otherwise it won't work.
### API usage:
``` js
WebAssembly.instantiateStreaming(fetch("pcg_prng.wasm")).then(({ instance }) => {
const seed = instance.exports.pcg32_srandom;
const biased = instance.exports.pcg32_random_biased;
const unbiased = instance.exports.pcg32_random_unbiased;
seed(BigInt(Date.now()), BigInt(Date.now()));
console.log(biased(20, 30), unbiased(20, 30));
});
```