Random.State(3)
β¨ NAME β¨
okay so welcome to Random.State(3), straight out of the OCaml library manual. The official name line is Random.State β and the description is literally no description. That's not me skipping it, bestie, that's the whole assignment ππ
π§ Module π§
The module is Random.State. That's it. That's the module. main character energy, no extra lore π«Ά
π Documentation π
Inside the docs, it opens with this:
Module State : sig end
slay, a signature wrapper. and then we get the actual PRNG-state content, which is where it gets good β¨
type tβ the type of PRNG states. short, mysterious, iconic.val make : int array -> tβ creates a new state and initializes it with the given seed. feed it anint array, get a state.val make_self_init : unit -> tβ creates a new state and initializes it with a random seed chosen in a system-dependent way. the seed is obtained as described inRandom.self_init. so it's giving "system, you pick" πval copy : t -> tβ returns a copy of the given state. duplicate the vibe, no cap.
Then the big group chat of random-draw functions. These are the same as the basic functions, except that they use (and update) the given PRNG state instead of the default one. That's the whole secret, and yes it's lowkey the most important line here π₯
val bits : t -> intval int : t -> int -> intval full_int : t -> int -> intval int_in_range : t -> min:int -> max:int -> intval int32 : t -> Int32.t -> Int32.tval int32_in_range : t -> min:int32 -> max:int32 -> int32val nativeint : t -> Nativeint.t -> Nativeint.tval nativeint_in_range : t -> min:nativeint -> max:nativeint -> nativeintval int64 : t -> Int64.t -> Int64.tval int64_in_range : t -> min:int64 -> max:int64 -> int64val float : t -> float -> floatval bool : t -> boolval bits32 : t -> Int32.tval bits64 : t -> Int64.tval nativebits : t -> Nativeint.tval split : t -> tβ draws a fresh PRNG state from the given PRNG state. (the given PRNG state is modified.) the new PRNG is statistically independent from the given PRNG. data can be drawn from both PRNGs, in any order, without risk of correlation. both PRNGs can be split later, arbitrarily many times. Since 5.0. literally spawning independent little random universes ππval to_binary_string : t -> stringβ serializes the PRNG state into an immutable sequence of bytes. seeRandom.State.of_binary_stringfor deserialization. thestringtype is intended here for serialization only: the encoding is not human-readable and may not be printable. note that the serialization format may differ across OCaml versions. Since 5.1. it's giving "save the state, but make it bytes" π₯val of_binary_string : string -> tβ deserializes a byte sequence obtained by callingRandom.State.to_binary_string. the resulting PRNG state will produce the same random numbers as the state that was passed as input toRandom.State.to_binary_string. Since 5.1. raisesFailureif the input is not in the expected format. note that the serialization format may differ across OCaml versions.
unlike the functions provided by theMarshalmodule, this function either produces a valid state or fails cleanly with aFailureexception. it can be safely used on user-provided, untrusted inputs. that's a big slay for safety πβ¨
π mwah π this little page was brought to you by OCamldoc, dated 2026-06-22, and filed under Random.State(3). byeee π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms