Module Random.StateSource

The functions from module State manipulate the current state of the random generator explicitly. This allows using one or several deterministic PRNGs, even in a multi-threaded program, without interference from other parts of the program.

Note that Random.get_state from the standard library is not exposed, because it misleadingly makes a copy of random state, which is not typically the desired outcome for accessing the shared state.

Obtaining multiple generators with good independence properties is nontrivial; see the Splittable_random library for that.

Sourcetype t
Sourceval default : t

This gives access to the default random state, allowing user code to share (and thereby mutate) the random state used by the main functions in Random.

Sourceval make : int array -> t

Creates a new state and initializes it with the given seed.

Sourceval make_self_init : ?allow_in_tests:bool -> unit -> t

Creates a new state and initializes it with a system-dependent low-entropy seed.

Sourceval copy : t -> t

These functions are the same as the basic functions, except that they use (and update) the given PRNG state instead of the default one.

Sourceval bits : t -> int
Sourceval bits64 : t -> int64
Sourceval int : t -> int -> int
Sourceval int32 : t -> int32 -> int32
Sourceval nativeint : t -> nativeint -> nativeint
Sourceval int64 : t -> int64 -> int64
Sourceval float : t -> float -> float
Sourceval int_incl : t -> int -> int -> int
Sourceval int32_incl : t -> int32 -> int32 -> int32
Sourceval nativeint_incl : t -> nativeint -> nativeint -> nativeint
Sourceval int64_incl : t -> int64 -> int64 -> int64
Sourceval float_range : t -> float -> float -> float
Sourceval bool : t -> bool
Sourceval char : t -> char
Sourceval ascii : t -> char