Legend:
Library
Module
Module type
Parameter
Class
Class type
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
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.
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.
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.