package stdlib-random

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type t

The type of PRNG states.

val make : int array -> t

Create a new state and initialize it with the given seed.

val make_self_init : unit -> t

Create a new state and initialize it with a system-dependent low-entropy seed.

val copy : t -> t

Return a copy of the given state.

val bits : t -> int
val int : t -> int -> int
val full_int : t -> int -> int
val int_in_range : t -> min:int -> max:int -> int
val int32 : t -> Int32.t -> Int32.t
val int32_in_range : t -> min:int32 -> max:int32 -> int32
val nativeint : t -> Nativeint.t -> Nativeint.t
val nativeint_in_range : t -> min:nativeint -> max:nativeint -> nativeint
val int64 : t -> Int64.t -> Int64.t
val int64_in_range : t -> min:int64 -> max:int64 -> int64
val float : t -> float -> float
val bool : t -> bool
val bits32 : t -> Int32.t
val bits64 : t -> Int64.t
val nativebits : t -> Nativeint.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.

val to_binary_string : t -> string

Serializes the PRNG state into an immutable sequence of bytes. See of_binary_string for deserialization.

The string type is intended here for serialization only, the encoding is not human-readable and may not be printable.

Note that the serialization format may differ across OCaml versions.

  • since 5.1
val of_binary_string : string -> t

Deserializes a byte sequence obtained by calling to_binary_string. The resulting PRNG state will produce the same random numbers as the state that was passed as input to to_binary_string.

  • raises Failure

    if the input is not in the expected format.

    Note that the serialization format may differ across OCaml versions.

    Unlike the functions provided by the Marshal module, this function either produces a valid state or fails cleanly with a Failure exception. It can be safely used on user-provided, untrusted inputs.

  • since 5.1
OCaml

Innovation. Community. Security.