package xoshiro

  1. Overview
  2. Docs

Xoshiro

This library includes OCaml implementation of some pseudorandom number generators (PRNGs) designed by David Blackman and Sebastiano Vigna behind an interface that mimmics that of the Random module of the standard library.

The Xoshiro generators (for XOR/shift/rotate) are all-purpose generators (not cryptographically secure). Compared to the standard library, they:

  • have a bigger state space: xoshiro256++/xoshiro256** generators have a period of 2²⁵⁶-1.
  • pass more tests: xoshiro256++/xoshiro256** pass the whole BigCrush test suite while the Random module of the standard library systematically fails some of the tests.
  • run similarly fast for the bindings and twice slower for the pure implementation.

This module and all the variants (see below) are drop-in replacements of the Random module of the standard library. This means you can use Xoshiro everywhere where you would use Random. For instance:

  • use Xoshiro.bits instead of Random.bits
  • (same for int, bool, etc. and also for the State submodule)
  • use open Xoshiro instead of open Random
  • or even write module Random = Xoshiro at the beginning of every file.

Variants

David Blackman and Sebastiano Vigna present several variants of their generators depending on the state size and implementation details.

module Xoshiro256plusplus : sig ... end

Default

The module Xoshiro includes by default an implementation of Xoshiro256plusplus.

include module type of Xoshiro256plusplus
include MakeRandom.Sig.Full
val init : int -> unit
val full_init : int array -> unit
val self_init : unit -> unit
val bits : unit -> int
val int : int -> int
val int32 : Stdlib.Int32.t -> Stdlib.Int32.t
val nativeint : Stdlib.Nativeint.t -> Stdlib.Nativeint.t
val int64 : Stdlib.Int64.t -> Stdlib.Int64.t
val float : float -> float
val bool : unit -> bool
module State : sig ... end
val get_state : unit -> State.t
val set_state : State.t -> unit

Low-level Interface

Direct bindings of the functions provided in the original implementation.

module LowLevel : sig ... end

Others

module Splitmix64 : MakeRandom.Sig.Full
OCaml

Innovation. Community. Security.