package bitgenerators

  1. Overview
  2. Docs

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.

The Philox state vector consists of a 256-bit value encoded as a 4-element unsigned 64-bit tuple and a 128-bit value encoded as a 2-element unsigned 64-bit tuple. The former is a counter which is incremented by 1 for every 4 64-bit randoms produced. The second is a key which determined the sequence produced. Using different keys produces independent sequences.

SeedSequence is used to produce a high-quality initial state for the key vector. The counter is set to 0.

The preferred way to use Philox in parallel applications is to use the SeedSequence.spawn function to obtain entropy values, and to use these to generate new instance of a Philox bitgenerator:

open Bitgen
let gens =
    SeedSequence.initialize []
    |> SeedSequence.spawn 10
    |> fst
    |> List.map Philox4x64.initialize
type t

t is the state of the bitgenerator.

val next_uint64 : t -> Stdint.uint64 * t

next_uint64 t Generates a random unsigned 64-bit integer and a state of the generator advanced forward by one step.

val next_uint32 : t -> Stdint.uint32 * t

next_uint32 t Generates a random unsigned 32-bit integer and a state of the generator advanced forward by one step.

val next_bounded_uint64 : Stdint.uint64 -> t -> Stdint.uint64 * t

next_bounded_uint64 b t Generates a random unsigned 64-bit integer in the interval [0, b). It returns the integer as well as the state of the generator advanced forward. To generate an integer in the range [a, b), one should generate an integer in [0, b - a) using next_bounded_uint64 (b - a) t and then add a to the resulting integer to get the output in the desired range.

val next_double : t -> float * t

next_double t Generates a random 64 bit float and a state of the generator advanced forward by one step.

val initialize : Bitgen__.Seed.SeedSequence.t -> t

initialize s Returns the initial state of the generator. The random stream is determined by the initialization of the seed sequence s of SeedSequence.t type.

val initialize_ctr : counter:(Stdint.uint64 * Stdint.uint64 * Stdint.uint64 * Stdint.uint64) -> Bitgen__.Seed.SeedSequence.t -> t

Get the initial state of the generator using a 4-element unsigned 64-bit tuple as the bitgenerator's counter initial state as well as SeedSequence.t for the initiale state of the generator's key.

val jump : t -> t

jump t is equivalent to 2^{128} calls to Philox4x64.next_uint64.

advance n Advances the generator forward as if n draws have been made, and returns the new advanced state.

OCaml

Innovation. Community. Security.