# FreeBSD Manual Pages

Random(3) OCamldoc Random(3)NAMERandom - Pseudo-random number generators (PRNG).ModuleModule RandomDocumentationModuleRandom:sigendPseudo-random number generators (PRNG).===Basicfunctions===valinit:int->unitInitialize the generator, using the argument as a seed. The same seed will always yield the same sequence of numbers.valfull_init:intarray->unitSame asRandom.initbut takes more data as seed.valself_init:unit->unitInitialize the generator with a random seed chosen in a system-depen- dent way. If/dev/urandomis 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).valbits:unit->intReturn 30 random bits in a nonnegative integer.Before3.12.0used a different algorithm (affects all the following functions)valint:int->intRandom.intboundreturns a random integer between 0 (inclusive) andbound(exclusive).boundmust be greater than 0 and less than 2^{30.valint32:Int32.t->Int32.tRandom.int32boundreturns a random integer between 0 (inclusive) andbound(exclusive).boundmust be greater than 0.valnativeint:Nativeint.t->Nativeint.tRandom.nativeintboundreturns a random integer between 0 (inclusive) andbound(exclusive).boundmust be greater than 0.valint64:Int64.t->Int64.tRandom.int64boundreturns a random integer between 0 (inclusive) andbound(exclusive).boundmust be greater than 0.valfloat:float->floatRandom.floatboundreturns a random floating-point number between 0 andbound(inclusive). Ifboundis negative, the result is negative or zero. Ifboundis 0, the result is 0.valbool:unit->boolRandom.bool()returnstrueorfalsewith probability 0.5 each.===Advancedfunctions======ThefunctionsfrommoduleRandom.Statemanipulatethecurrentstateoftherandomgeneratorexplicitly.ThisallowsusingoneorseveraldeterministicPRNGs,eveninamulti-threadedprogram,withoutinter-ferencefromotherpartsoftheprogram.===moduleState:sigendvalget_state:unit->State.tReturn the current state of the generator used by the basic functions.valset_state:State.t->unitSet the state of the generator used by the basic functions. 2021-08-28 source: Random(3)

NAME | Module | Documentation

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=Random&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>