man-pages/man3/Stdlib.Random.3o.html
2021-03-31 01:06:50 +01:00

296 lines
3.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Stdlib.Random</TITLE>
</HEAD><BODY>
<H1>Stdlib.Random</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Stdlib.Random - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Stdlib.Random
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Random</B>
<BR>&nbsp;:&nbsp;
<B>(module Stdlib__random)</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<A NAME="lbAE">&nbsp;</A>
<H3>Basic functions</H3>
<P>
<P>
<P>
<I>val init </I>
:
<B>int -&gt; unit</B>
<P>
Initialize the generator, using the argument as a seed.
The same seed will always yield the same sequence of numbers.
<P>
<P>
<P>
<I>val full_init </I>
:
<B>int array -&gt; unit</B>
<P>
Same as
<B>Random.init</B>
but takes more data as seed.
<P>
<P>
<P>
<I>val self_init </I>
:
<B>unit -&gt; unit</B>
<P>
Initialize the generator with a random seed chosen
in a system-dependent way. If
<B>/dev/urandom</B>
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).
<P>
<P>
<P>
<I>val bits </I>
:
<B>unit -&gt; int</B>
<P>
Return 30 random bits in a nonnegative integer.
<P>
<P>
<B>Before3.12.0</B>
used a different algorithm (affects all the following
functions)
<P>
<P>
<P>
<P>
<I>val int </I>
:
<B>int -&gt; int</B>
<P>
<P>
<B>Random.int bound</B>
returns a random integer between 0 (inclusive)
and
<B>bound</B>
(exclusive).
<B>bound</B>
must be greater than 0 and less
than 2^30.
<P>
<P>
<P>
<I>val int32 </I>
:
<B>Int32.t -&gt; Int32.t</B>
<P>
<P>
<B>Random.int32 bound</B>
returns a random integer between 0 (inclusive)
and
<B>bound</B>
(exclusive).
<B>bound</B>
must be greater than 0.
<P>
<P>
<P>
<I>val nativeint </I>
:
<B>Nativeint.t -&gt; Nativeint.t</B>
<P>
<P>
<B>Random.nativeint bound</B>
returns a random integer between 0 (inclusive)
and
<B>bound</B>
(exclusive).
<B>bound</B>
must be greater than 0.
<P>
<P>
<P>
<I>val int64 </I>
:
<B>Int64.t -&gt; Int64.t</B>
<P>
<P>
<B>Random.int64 bound</B>
returns a random integer between 0 (inclusive)
and
<B>bound</B>
(exclusive).
<B>bound</B>
must be greater than 0.
<P>
<P>
<P>
<I>val float </I>
:
<B>float -&gt; float</B>
<P>
<P>
<B>Random.float bound</B>
returns a random floating-point number
between 0 and
<B>bound</B>
(inclusive). If
<B>bound</B>
is
negative, the result is negative or zero. If
<B>bound</B>
is 0,
the result is 0.
<P>
<P>
<P>
<I>val bool </I>
:
<B>unit -&gt; bool</B>
<P>
<P>
<B>Random.bool ()</B>
returns
<B>true</B>
or
<B>false</B>
with probability 0.5 each.
<P>
<P>
<P>
<P>
<A NAME="lbAF">&nbsp;</A>
<H3>Advanced functions</H3>
<P>
<P>
<P>
<P>
The functions from module
<B>Random.State</B>
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.
<P>
<I>module State : </I>
<B>sig end</B>
<P>
<P>
<P>
<P>
<P>
<I>val get_state </I>
:
<B>unit -&gt; State.t</B>
<P>
Return the current state of the generator used by the basic functions.
<P>
<P>
<P>
<I>val set_state </I>
:
<B>State.t -&gt; unit</B>
<P>
Set the state of the generator used by the basic functions.
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
<DL>
<DT id="4"><A HREF="#lbAE">Basic functions</A><DD>
<DT id="5"><A HREF="#lbAF">Advanced functions</A><DD>
</DL>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:57 GMT, March 31, 2021
</BODY>
</HTML>