jon.recoil.org

Module Splittable_randomSource

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 split operation for generating new pseudo-random states. While it is easy to simulate 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 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.

Sourcetype t

Create a new t seeded from the given random state. This allows nondeterministic initialization, for example in the case that the input state was created using Random.make_self_init.

Constructors like create and of_int should be called once at the start of a randomized computation and the resulting state should be threaded through. Repeatedly creating splittable random states from seeds in the middle of computation can defeat the SPRNG's splittable properties.

Sourceval of_int : Base.int -> Splittable_random.t @@ portable

Create a new t that will return identical results to any other t created with that integer.

Sourceval perturb : Splittable_random.t -> Base.int -> Base.unit @@ portable

perturb t salt adds the entropy of salt to t.

Sourceval copy : Splittable_random.t @ shared -> Splittable_random.t @@ portable

Create a copy of t that will return the same random samples as t.

Sourceval copy_into_capsule : Splittable_random.t @ shared -> (Splittable_random.t, 'k) Capsule_expert.Data.t @@ portable

Like copy, but puts the result in an arbitrary capsule.

split t produces a new state that behaves deterministically (i.e. only depending on the state of t), but pseudo-independently from t. This operation mutates t, i.e., t will return different values than if this hadn't been called.

Sourceval split_into_capsule : Splittable_random.t -> (Splittable_random.t, 'k) Capsule_expert.Data.t @@ portable

Like split, but puts the result into an arbitrary capsule.

Sourcemodule State : sig ... end

Legacy aliases for the preceding definitions.

Sourceval bool : Splittable_random.t -> Base.bool @@ portable

Produces a random, fair boolean.

Sourceval int : Splittable_random.t -> lo:Base.int -> hi:Base.int -> Base.int @@ portable

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

Sourceval int32 : Splittable_random.t -> lo:Base.int32 -> hi:Base.int32 -> Base.int32 @@ portable
Sourceval int63 : Splittable_random.t -> lo:Base.Int63.t -> hi:Base.Int63.t -> Base.Int63.t @@ portable
Sourceval int64 : Splittable_random.t -> lo:Base.int64 -> hi:Base.int64 -> Base.int64 @@ portable
Sourceval nativeint : Splittable_random.t -> lo:Base.nativeint -> hi:Base.nativeint -> Base.nativeint @@ portable
Sourceval float : Splittable_random.t -> lo:Base.float -> hi:Base.float -> Base.float @@ portable
Sourceval unit_float : Splittable_random.t -> Base.float @@ portable

unit_float state = float state ~lo:0. ~hi:1., but slightly more efficient (and right endpoint is exclusive).

Sourcemodule Log_uniform : sig ... end