The package provides multiple pseudo-random number generators.
Note: The PRNGs generate statistical pseudo-random numbers. They are not cryptographically secure.
Currently implemented generators:
The package is published on Mops and GitHub. Please refer to the README on GitHub where it renders properly with formulas and tables.
API documentation: here on Mops
For updates, help, questions, feedback and other requests related to this package join us on:
You need mops
installed. In your project directory run:
mops add prng
In the Motoko source file import the package as one of:
import Prng "mo:prng";
import Prng "mo:prng";
let seed : Nat64 = 0;
let rng = Prng.Seiran128();
rng.init(seed);
rng.next();
rng.next();
let rng2 = Prng.SFCa(); // SFCa is compatible to numpy
rng2.init(seed);
rng.next();
rng.next();
You need moc
and wasmtime
installed.
Then run:
git clone git@github.com:research-ag/prng.git
make -C test
The benchmarking code can be found here: canister-profiling
Wasm instructios per invocation of next()
.
method | Seiran128 | SFC64 | SFC32 |
---|---|---|---|
next | 251 | 377 | 253 |
Heap allocation per invocation of next()
.
method | Seiran128 | SFC64 | SFC32 |
---|---|---|---|
next | 36 | 48 | 8 |
MR Research AG, 2023
Main author: react0r-com
Contributors: Timo Hanke (timohanke)
Apache-2.0