Page
Library
Module
Module type
Parameter
Class
Class type
Source
PRNG.STATEval seed : string -> tInitialize a generator from the given seed. The seed is given as a character string. The length and randomness of the seed limit the total entropy of the generator. For example, 64 bits of entropy can be obtained by giving a seed consisting of 8 cryptographically-strong random characters, as obtained e.g. by reading /dev/random.
val make : int array -> tInitialize a generator from the given seed. The seed is given as a character string. The length and randomness of the seed limit the total entropy of the generator. For example, 64 bits of entropy can be obtained by giving a seed consisting of 8 cryptographically-strong random characters, as obtained e.g. by reading /dev/random.
Initialize a generator from the given seed. The seed is given as an array of integers.
val make_self_init : unit -> tInitialize a generator from the given seed. The seed is given as an array of integers.
Initialize a generator from a random seed obtained from the operating system. Tries hard to provide at least 64 bits of entropy. With high probability, successive calls to make_self_init return different PRNGs with different seeds.
val bool : t -> boolval bit : t -> boolReturn a Boolean value in false,true with 0.5 probability each.
val uniform : t -> floatReturn a floating-point number evenly distributed between 0.0 and 1.0. 0.0 and 1.0 are never returned. The result is of the form n * 2{^-53}, where n is a random integer in (0, 2{^53}).
val float : t -> float -> floatfloat g x returns a floating-point number evenly distributed between 0.0 and x. If x is negative, negative numbers between x and 0.0 are returned. Implemented as uniform g *. x. Consequently, the values 0.0 and x can be returned (as a result of floating-point rounding), but not if x is 1.0, since float g 1.0 behaves exactly like uniform g.
val byte : t -> intval bits8 : t -> intReturn an 8-bit integer evenly distributed between 0 and 255.
val bits : t -> intval bits30 : t -> intReturn a 30-bit integer evenly distributed between 0 and 230-1 (that is, 1073741823, or 0x3FFFFFFF).
val int : t -> int -> intint g n returns an integer evenly distributed between 0 included and n excluded. Hence there are n possible return values with probability 1/n each. n must be greater than 0 and no greater than 230-1.
val bits32 : t -> int32Return a 32-bit integer evenly distributed between Int32.min_int and Int32.max_int.
val int32 : t -> int32 -> int32int32 g n returns a 32-bit integer evenly distributed between 0 included and n excluded. n must be strictly positive.
Note that int32 Int32.max_int produces numbers between 0 and Int32.max_int excluded. To produce numbers between 0 and Int32.max_int included, use Int32.logand (bits32 g) Int32.max_int.
val bits64 : t -> int64Return a 64-bit integer evenly distributed between Int64.min_int and Int64.max_int.
val int64 : t -> int64 -> int64int64 g n returns a 64-bit integer evenly distributed between 0 included and n excluded. n must be strictly positive.
Note that int64 Int64.max_int produces numbers between 0 and Int64.max_int excluded. To produce numbers between 0 and Int64.max_int included, use Int64.logand (bits64 g) Int64.max_int.
val nativebits : t -> nativeintnativebits g returns a platform-native integer (32 or 64 bits) evenly distributed between Nativeint.min_int and Nativeint.max_int.
val nativeint : t -> nativeint -> nativeintnativeint g n returns a platform-native integer between 0 included and n included. n must be strictly positive.
val char : t -> charReturn a character evenly distributed among '\000' ... '\255'.
val bytes : t -> bytes -> int -> int -> unitbytes g b ofs len produces len bytes of pseudo-random data and stores them in byte sequence b at offsets ofs to ofs+len-1.
Raise Invalid_argument if len < 0 or ofs and len do not designate a valid range of b.
split g returns a fresh generator g' that is statistically independent from the current generator g. The two generators g and g' can be used in parallel and will produce independent pseudo-random data. Each generator g and g' can be splitted again in the future.
copy g returns a generator g' that has the same state as g. The two generators g and g' produce the same data.
val reseed : t -> string -> unitreseed g s reinitializes the generator g with fresh seed data from string s. This is like seed s except that the existing generator g is seeded, instead of a new generator being returned. It is good practice to reseed a PRNG after a certain quantity of pseudo-random data has been produced from it: typically 232 numbers for the PRNG.Splitmix generator and 264 bytes for the PRNG.Chacha generator.
val remake : t -> int array -> unitreseed g s reinitializes the generator g with fresh seed data from string s. This is like seed s except that the existing generator g is seeded, instead of a new generator being returned. It is good practice to reseed a PRNG after a certain quantity of pseudo-random data has been produced from it: typically 232 numbers for the PRNG.Splitmix generator and 264 bytes for the PRNG.Chacha generator.
remake g a reinitializes the generator g with fresh seed data from array a. This is like reseed except that the seed is given as an array of integers.