Module MtRand


module MtRand: sig  end
Mersenne Twister PRNG


Ocaml version of the Mersenne Twister random number generator.

The interface of this pretty much follows the C reference version. It also produces the same output for a given seed as the reference version, of course.



The seed functions.



Only one call to one of these is needed. This should be enough variety.

val init32 : int32 -> unit
Seed from an int32 value.
val init : int -> unit
Seed from an int value.
val init_array32 : int32 array -> unit
Seed from an int32 array of any length.
val init_array : int array -> unit
Seed from an int array of any length.
val init_bigarray32 : (int32, Bigarray.int32_elt, 'a) Bigarray.Array1.t -> unit
Seed from an int32 bigarray of any length.
val init_genarray : ('a -> int32) -> 'a array -> unit
Seed from an int32 array generated by calling Array.map on f and the array.
val init_from_file : string -> unit
Seed from raw data in a file. The files used should hold at least 700 ints
val init_from_channel : Pervasives.in_channel -> unit
val init_from_descr : Unix.file_descr -> unit
val urandom_found : unit -> bool
Seed from /dev/urandom
val urandom_init : unit -> unit
val self_init : unit -> unit
Seed from /dev/urandom, or a default seed based on time and pid if /dev/urandom isn't available


Functions returning random numbers



All of these but the int64 ones produce the same output as the reference C code.

val uint32 : unit -> int32
Unsigned int32. Range: 0 <= x <= 0xffffffff
val int32 : unit -> int32
Signed int32. Range: 0 <= x <= 0x7fffffff
val uint64 : unit -> int64
val int64 : unit -> int64
val unativeint : unit -> nativeint
Unsigned nativeint.
val nativeint : unit -> nativeint
Signed nativeint
val uint : unit -> int
Unsigned int. Range: 0 <= x <= 0x7fffffff or 0 <= x <= 0x7fffffffffffffff
val int : unit -> int
Signed int. Range: 0 <= x <= 0x3fffffff or 0 <= x <= 0x3fffffffffffffff
val real1 : unit -> float
Range: 0 <= x <= 1
val real2 : unit -> float
Range: 0 <= x < 1
val real3 : unit -> float
Range: 0 < x < 1
val res53 : unit -> float
Range: 0 <= x < 1 with 53-bit resolution
module IntSource: sig  end
Sources for use with the Rand distributions
module Int32Source: sig  end
module FloatSource: sig  end