Legend:
Library
Module
Module type
Parameter
Class
Class type
This library provides implementations of Psuedo-random number generators using an interface heavily inspired by numpy's numpy.random module.
The implementation is functional and requires the user to explicitely manage state of a bitgenerator. It also provides an mechanism to ensure that each generator is initialized using a high quality initial states by passing input seed through SeedSequence (see: this blog post.
Below is a highlevel example of one can generate a list of
open Bitgen
open Stdint
let rng = SeedSequence.initialize [Uint128.of_int 12345] |> PCG64.initialize in
Seq.unfold (fun t -> Some (PCG64.next_double t)) rng |> Seq.take 10 |> List.of_seq
(* - : float list =
[0.227336022467169663; 0.316758339709752867; 0.797365457332734118;
0.676254670750974562; 0.391109550601909; 0.332813927866384529;
0.598308753587189823; 0.186734185603713354; 0.672756044014621302;
0.941802865269937173] *)
SFC64 is a 256-bit implementation of Chris Doty-Humphrey's Small Fast Chaotic PRNG. It has a few different cycles that one might be on, depending on the seed; the expected period will be about 2^{255}.
PCG-64 is a 128-bit implementation of O'Neill's permutation congruential generator. PCG-64 has a period of 2^{128} and supports advancing an arbitrary number of steps as well as 2^{127} streams.
Xoshiro256** is a 64-bit PRNG that uses a carefully constructed linear transformation. This produces a fast PRNG with excellent statistical quality. Xoshiro256** has a period of 2^{256} - 1 and supports jumping the sequence in increments of 2^{128} which allows multiple non-overlapping subsequences to be generated.
Philox4x64 (a mnemonic for Product HI LO Xor) is a 64-bit PRNG that uses a counter-based design based on weaker (and faster) versions of cryptographic functions. Instances using different values of the key produce independent sequences. Philox has a period of 2^{256} - 1 and supports arbitrary advancing and jumping the sequence in increments of 2^{128}. These features allow multiple non-overlapping sequences to be generated. Philox's round function is applied 10 times each time the PRNG is advanced forward.
ChaCha is a 64-bit PRNG that uses a counter-based design based on the ChaCha cipher. Instances using different values of the key produce sequences. ChaCha has a period of 2^{128} and supports arbitrary advancing and jumping the sequence in increments of 2^{64}. These features allow multiple non-overlapping sequences to be generated.