A splittable pseudo-random number generator (SPRNG) functions like a PRNG in that it can be used as a stream of random values; it can also be "split" to produce a second, independent stream of random values. This module implements a splittable pseudo-random number generator that sacrifices cryptographic-quality randomness in favor of performance.
The primary difference between Splittable_random
and Random is the State.split
operation for generating new pseudo-random states. While it is easy to simulate
State.split
using Random
, the result has undesirable statistical properties; the
new state does not behave independently of the original. It is better to switch to
Splittable_random
if you need an operation like State.split
, as this module has
been implemented with the statistical properties of splitting in mind. For most other
purposes, Random
is likely a better choice, as its implementation passes all Diehard
tests, while Splittable_random
fails some Diehard tests.
module State : sig ... end
val int : State.t ‑> lo:Core_kernel__.Import.int ‑> hi:Core_kernel__.Import.int ‑> Core_kernel__.Import.int
Produce a random number uniformly distributed in the given inclusive range. (In the
case of float
, hi
may or may not be attainable, depending on rounding.)
val int32 : State.t ‑> lo:Core_kernel__.Import.int32 ‑> hi:Core_kernel__.Import.int32 ‑> Core_kernel__.Import.int32
val int64 : State.t ‑> lo:Core_kernel__.Import.int64 ‑> hi:Core_kernel__.Import.int64 ‑> Core_kernel__.Import.int64
val nativeint : State.t ‑> lo:Core_kernel__.Import.nativeint ‑> hi:Core_kernel__.Import.nativeint ‑> Core_kernel__.Import.nativeint
val float : State.t ‑> lo:Core_kernel__.Import.float ‑> hi:Core_kernel__.Import.float ‑> Core_kernel__.Import.float
val unit_float : State.t ‑> Core_kernel__.Import.float
unit_float state = float state ~lo:0. ~hi:1.
, but slightly more efficient (and
right endpoint is exclusive).