npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tiny-prng-wasm

v0.2.5

Published

PRNG in the browser stack

Readme

Tiny PRNG

codecov

[!NOTE] Beta release. The quality of generated pseudo random numbers is not tested at now.

This crate provides common psuedo random number generators written in pure Rust, which include:

| name | supported mode | cycle period | reference | |------------------|---------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Mersenne Twister | MT19937 MT19937_64 | 219937-1 | Saitoh and Matsumoto (1997) | | Xorshift | xorshift32 xorshift64xorshift128xorshift64*xorshift1024* | 264-1 264-1 2128-1 264-1 21024-1 | Marsaglia (2003), J. Stat. Softw. 8 (14) Vigna (2016), ACM Trans. Math. Softw. Vol. 42 (4), 30 | | PCG (with LCG) | PCG-XSL-RR-128/64 PCG-XSH-RS-64/32 PCG-XSH-RR-64/32 | 2128 264 264 | O'Neil (2014), HMC-CS-2014-0905Reference implementation |

This library is written in Rust but you can use it from JavaScript via its WASM binary!

For web developers who need to generate many pseudo random numbers, we also provide the npm package tiny-prng-wasm. Install it as follows:

npm install tiny-prng-wasm

API

Available constructors

In the npm package, three PRNGs (and one mode for each) are supported:

  • Pcg (PCG-XSL-RR-128/64)
  • Xorshift64 (Xorshift64)
  • Mt64 (MT19937_64)

Each of them can be instantiated with its constructor with a seed value:

let generator = new Pcg(1274671829);
console.log(generate.generate());

[!WARNING] Be careful to choose a certain randomness source to get a seed for the generator.

These generators are not cryptographically secure random number generators, and a value sequence generated by the one of these generators is perfectly predictable from the set of the algorithm and its seed value.

Available methods

Each generator have identical set of methods for the API. Following operations are supported.

generate

The generate method generates a pseudo random number in unsigned integer.

let g = new Pcg(1826533);
console.log(g.generate());

generate_list

The generate_list method generates a list of pseudo random numbers with count

let g = new Pcg(1826533);
let count = 1000;
let list = g.generate_list(count);
console.log(list[100], list[200]);

generate_real

The generate_real method generates a pseudo random number in a real number between [0,1].

let g = new Pcg(1826533);
console.log(g.generate_real());

generate_real_list

The generate_real_list method generates a list of pseudo random numbers in a real number between [0,1], with count

let g = new Pcg(1826533);
let count = 1000;
let list = g.generate_real_list(count);
console.log(list[100], list[200]);

generate_real_ranged

The generate_real_ranged generates a pseudo random number in a real number between specified minimal and maximal values.

let g = new Pcg(1826533);
console.log(g.generate_real_ranged(0, Math.PI)); // results

generate_real_ranged_list

The generate_real_ranged_list generates a list of pseudo random numbers in a real number between minimal and maximal values, with specified count.

let g = new Pcg(1826533);
let count = 1000;
let list = g.generate_real_ranged(0, Math.PI, count);
console.log(list[100], list[200]);

Benchmarking

Library Routine

Any core routines in the library can generate a pseudo random number within 30 msec. (But you need to built the generator instance with seed before its working.)

See the bench result for 10 million instructions of pseudo random number generation:

user@localhost tiny_prng $  cargo bench  | grep -v ignored
# (output omitted...)
running 31 tests
test mt64::tests::bench_mt19937_10mil          ... bench:   7,660,233.30 ns/iter (+/- 43,981.22)
test mt::tests::bench_mt19937_32_10mil         ... bench:   9,339,750.10 ns/iter (+/- 415,492.15)
test pcg::tests::bench_pcgxshrr6432_10mil      ... bench:   9,416,045.80 ns/iter (+/- 589,289.98)
test pcg::tests::bench_pcgxslrr12864_10mil     ... bench:  15,627,133.30 ns/iter (+/- 260,361.14)
test xorshift::tests::bench_xorshift1024_10mil ... bench:  23,095,120.80 ns/iter (+/- 7,339,056.80)
test xorshift::tests::bench_xorshift64_10mil   ... bench:  18,749,149.90 ns/iter (+/- 186,877.62)

Execution environment:

  • OS: macOS Sequoia 15.5
  • CPU: arm64 (Apple M1)
  • Memory: 8GB

[!NOTE] This result is measured with benchmark tests in the library. We are planning further performance evaluations and investigations in the future, in more different execution environments with variety of benchmarking conditions.

Frontend Benchmarking

As the simplest web benchmarking environment, you can try the online benchmarking in your browser.

Simply run make under the wasm_web directory and open http://localhost:8080.

Author

Tiny PRNG Wasm contributors