.TH "Random" 3o 2023-09-18 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 .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 full_int : .B int -> int .sp .ft B Random\&.full_int bound .ft R returns a random integer between 0 (inclusive) and .ft B bound .ft R (exclusive)\&. .ft B bound .ft R may be any positive integer\&. .sp If .ft B bound .ft R is less than 2^30, .ft B Random\&.full_int bound .ft R is equal to .ft B Random\&.int .ft R .ft B bound .ft R \&. If .ft B bound .ft R is greater than 2^30 (on 64\-bit systems or non\-standard environments, such as JavaScript), .ft B Random\&.full_int .ft R returns a value, where .ft B Random\&.int .ft R raises .ft B Invalid_argument .ft R \&. .sp .B "Since" 4.13.0 .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 .I val bits32 : .B unit -> Int32.t .sp .ft B Random\&.bits32 () .ft R returns 32 random bits as an integer between .ft B Int32\&.min_int .ft R and .ft B Int32\&.max_int .ft R \&. .sp .B "Since" 4.14.0 .sp .I val bits64 : .B unit -> Int64.t .sp .ft B Random\&.bits64 () .ft R returns 64 random bits as an integer between .ft B Int64\&.min_int .ft R and .ft B Int64\&.max_int .ft R \&. .sp .B "Since" 4.14.0 .sp .I val nativebits : .B unit -> Nativeint.t .sp .ft B Random\&.nativebits () .ft R returns 32 or 64 random bits (depending on the bit width of the platform) as an integer between .ft B Nativeint\&.min_int .ft R and .ft B Nativeint\&.max_int .ft R \&. .sp .B "Since" 4.14.0 .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