f0i / prng

Prngs for Motoko

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Statistical pseudo-random number generators for Motoko

Overview

The package provides multiple pseudo-random number generators.

Note: The PRNGs generate statistical pseudo-random numbers. They are not cryptographically secure.

Currently implemented generators:

Links

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:

Usage

Install with mops

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";

Example

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();

Build & test

You need moc and wasmtime installed. Then run:

git clone git@github.com:research-ag/prng.git
make -C test

Benchmarks

The benchmarking code can be found here: canister-profiling

Time

Wasm instructios per invocation of next().

method Seiran128 SFC64 SFC32
next 251 377 253

Memory

Heap allocation per invocation of next().

method Seiran128 SFC64 SFC32
next 36 48 8

Copyright

MR Research AG, 2023

Authors

Main author: react0r-com

Contributors: Timo Hanke (timohanke)

License

Apache-2.0

About

Prngs for Motoko

License:Apache License 2.0


Languages

Language:Motoko 98.5%Language:Makefile 1.5%