.TH "Stdlib.Random" 3o 2020-10-30 OCamldoc "OCaml library" .SH NAME Stdlib.Random \- no description .SH Module Module Stdlib.Random .SH Documentation .sp Module .BI "Random" : .B (module Stdlib__random) .sp .sp .sp .sp .PP .SS Basic functions .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 .ft B Random\&.init .ft R 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 .ft B /dev/urandom .ft R 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 .ft B Random\&.int bound .ft R returns a random integer between 0 (inclusive) and .ft B bound .ft R (exclusive)\&. .ft B bound .ft R must be greater than 0 and less than 2^30\&. .sp .I val int32 : .B Int32.t -> Int32.t .sp .ft B Random\&.int32 bound .ft R returns a random integer between 0 (inclusive) and .ft B bound .ft R (exclusive)\&. .ft B bound .ft R must be greater than 0\&. .sp .I val nativeint : .B Nativeint.t -> Nativeint.t .sp .ft B Random\&.nativeint bound .ft R returns a random integer between 0 (inclusive) and .ft B bound .ft R (exclusive)\&. .ft B bound .ft R must be greater than 0\&. .sp .I val int64 : .B Int64.t -> Int64.t .sp .ft B Random\&.int64 bound .ft R returns a random integer between 0 (inclusive) and .ft B bound .ft R (exclusive)\&. .ft B bound .ft R must be greater than 0\&. .sp .I val float : .B float -> float .sp .ft B Random\&.float bound .ft R returns a random floating\-point number between 0 and .ft B bound .ft R (inclusive)\&. If .ft B bound .ft R is negative, the result is negative or zero\&. If .ft B bound .ft R is 0, the result is 0\&. .sp .I val bool : .B unit -> bool .sp .ft B Random\&.bool () .ft R returns .ft B true .ft R or .ft B false .ft R with probability 0\&.5 each\&. .sp .PP .SS Advanced functions .PP .PP The functions from module .ft B Random\&.State .ft R 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\&. .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