.TH "Random" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Random \- Pseudo-random number generators (PRNG). .SH Module Module Random .SH Documentation .sp Module .BI "Random" : .B sig end .sp Pseudo\-random number generators (PRNG)\&. .sp .sp .sp .PP .B === .B Basic functions .B === .PP .I val init : .B int -> unit .sp Initialize the generator, using the argument as a seed\&. The same seed will always yield the same sequence of numbers\&. .sp .I val full_init : .B int array -> unit .sp Same as .B Random\&.init but takes more data as seed\&. .sp .I val self_init : .B unit -> unit .sp Initialize the generator with a random seed chosen in a system\-dependent way\&. If .B /dev/urandom is available on the host machine, it is used to provide a highly random initial seed\&. Otherwise, a less random seed is computed from system parameters (current time, process IDs)\&. .sp .I val bits : .B unit -> int .sp Return 30 random bits in a nonnegative integer\&. .sp .B "Before3.12.0" used a different algorithm (affects all the following functions) .sp .I val int : .B int -> int .sp .B Random\&.int bound returns a random integer between 0 (inclusive) and .B bound (exclusive)\&. .B bound must be greater than 0 and less than 2^{30\&. .sp .I val int32 : .B Int32.t -> Int32.t .sp .B Random\&.int32 bound returns a random integer between 0 (inclusive) and .B bound (exclusive)\&. .B bound must be greater than 0\&. .sp .I val nativeint : .B Nativeint.t -> Nativeint.t .sp .B Random\&.nativeint bound returns a random integer between 0 (inclusive) and .B bound (exclusive)\&. .B bound must be greater than 0\&. .sp .I val int64 : .B Int64.t -> Int64.t .sp .B Random\&.int64 bound returns a random integer between 0 (inclusive) and .B bound (exclusive)\&. .B bound must be greater than 0\&. .sp .I val float : .B float -> float .sp .B Random\&.float bound returns a random floating\-point number between 0 and .B bound (inclusive)\&. If .B bound is negative, the result is negative or zero\&. If .B bound is 0, the result is 0\&. .sp .I val bool : .B unit -> bool .sp .B Random\&.bool () returns .B true or .B false with probability 0\&.5 each\&. .sp .PP .B === .B Advanced functions .B === .PP .PP .B === The functions from module Random\&.State manipulate the current state .B of the random generator explicitly\&. .B This allows using one or several deterministic PRNGs, .B even in a multi\-threaded program, without interference from .B other parts of the program\&. === .PP .I module State : .B sig end .sp .sp .I val get_state : .B unit -> State.t .sp Return the current state of the generator used by the basic functions\&. .sp .I val set_state : .B State.t -> unit .sp Set the state of the generator used by the basic functions\&. .sp