package bitgenerators

  1. Overview
  2. Docs
PRNG bitgenerators for OCaml users

Install

Dune Dependency

Authors

Maintainers

Sources

v0.1.0.tar.gz
md5=46965587a11aa08c1e1a891f9fb12221
sha512=49423a091b05d67ee90b19d997da48f41eddabb285acdd04e1ab22f0bd6e8bccd47fe69e5b185813cc3b1c03627020d2dabd703b9c1de92869f0de118847d577

doc/bitgenerators/Bitgen/index.html

Module BitgenSource

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] *)
Sourcemodule 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.

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

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

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

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

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

OCaml

Innovation. Community. Security.