Module Bitgen

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] *)
module SeedSequence : sig ... end

SeedSequence mixes sources of entropy in a reproducible way to set the initial state for independent and very probably non-overlapping BitGenerators.

module SFC64 : sig ... end

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}.

module PCG64 : sig ... end

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.

module Xoshiro256 : sig ... end

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.

module Philox4x64 : sig ... end

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.

module ChaCha : sig ... end

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.

module LXM : sig ... end

The LXM generator combines two simple generators with an optional additional hashing of the output. The first generator is a LCG of with and update s = a s + b \mod 2^{64} where a is 2862933555777941757 and b is settable. The default value of b is 3037000493. The second is the standard 64-bit xorshift generator.

module EFIIX64x48 : sig ... end

EFIIX64x48 is a 64-bit PRNG that uses a set of tables to generate random values. This produces a fast PRNG with statistical quality similar to cryptographic generators but faster.