random.3: Some minor improvements to wording/clarity
This commit is contained in:
+37
-44
@@ -28,7 +28,7 @@
|
|||||||
.\" @(#)random.3 8.1 (Berkeley) 6/4/93
|
.\" @(#)random.3 8.1 (Berkeley) 6/4/93
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd April 22, 2019
|
.Dd January 20, 2020
|
||||||
.Dt RANDOM 3
|
.Dt RANDOM 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -60,7 +60,7 @@ Applications which require unpredictable random numbers should use
|
|||||||
instead.
|
instead.
|
||||||
.Ef
|
.Ef
|
||||||
.Pp
|
.Pp
|
||||||
The
|
Unless initialized with less than 32 bytes of state, the
|
||||||
.Fn random
|
.Fn random
|
||||||
function
|
function
|
||||||
uses a non-linear additive feedback random number generator employing a
|
uses a non-linear additive feedback random number generator employing a
|
||||||
@@ -72,53 +72,51 @@ The period of this random number generator is very large, approximately
|
|||||||
.if t 16\(mu(2\u\s731\s10\d\(mi1).
|
.if t 16\(mu(2\u\s731\s10\d\(mi1).
|
||||||
.if n 16*((2**31)\(mi1).
|
.if n 16*((2**31)\(mi1).
|
||||||
.Pp
|
.Pp
|
||||||
|
If initialized with less than 32 bytes of state,
|
||||||
|
.Fn random
|
||||||
|
uses the same poor-quality Park-Miller LCG as
|
||||||
|
.Xr rand 3 .
|
||||||
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn random
|
.Fn random
|
||||||
and
|
and
|
||||||
.Fn srandom
|
.Fn srandom
|
||||||
functions have (almost) the same calling sequence and initialization properties as the
|
functions are analagous to
|
||||||
.Xr rand 3
|
.Xr rand 3
|
||||||
and
|
and
|
||||||
.Xr srand 3
|
.Xr srand 3 .
|
||||||
functions.
|
|
||||||
The difference is that
|
The difference is that
|
||||||
.Xr rand 3
|
.Xr rand 3
|
||||||
produces a much less random sequence \(em in fact, the low dozen bits
|
is a worse pseudo-random number generator.
|
||||||
generated by rand go through a cyclic pattern.
|
|
||||||
All the bits generated by
|
|
||||||
.Fn random
|
|
||||||
are usable.
|
|
||||||
For example,
|
|
||||||
.Sq Li random()&01
|
|
||||||
will produce a random binary
|
|
||||||
value.
|
|
||||||
.Pp
|
.Pp
|
||||||
Like
|
Like
|
||||||
.Xr rand 3 ,
|
.Xr rand 3 ,
|
||||||
.Fn random
|
.Fn random
|
||||||
will by default produce a sequence of numbers that can be duplicated
|
is implicitly initialized as if
|
||||||
by calling
|
.Fn srandom "1"
|
||||||
.Fn srandom
|
had been invoked explicitly.
|
||||||
with
|
|
||||||
.Ql 1
|
|
||||||
as the seed.
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn srandomdev
|
.Fn srandomdev
|
||||||
routine initializes a state array using
|
routine initializes the state array using random numbers obtained from the
|
||||||
pseudo-random numbers obtained from the kernel.
|
kernel.
|
||||||
Note that this particular seeding
|
This can generate states which are impossible to reproduce by calling
|
||||||
procedure can generate states which are impossible to reproduce by
|
.Fn srandom ,
|
||||||
calling
|
because the succeeding terms in the state buffer are no longer derived from the
|
||||||
.Fn srandom
|
Park-Miller LCG algorithm applied to a fixed seed.
|
||||||
with any value, since the succeeding terms in the
|
|
||||||
state buffer are no longer derived from the LC algorithm applied to
|
|
||||||
a fixed seed.
|
|
||||||
.Pp
|
.Pp
|
||||||
The
|
The
|
||||||
.Fn initstate
|
.Fn initstate
|
||||||
routine allows a state array, passed in as an argument, to be initialized
|
routine initializes the provided state array of
|
||||||
for future use.
|
.Vt uint32_t
|
||||||
|
values and uses it in future
|
||||||
|
.Fn random
|
||||||
|
invocations.
|
||||||
|
(Despite the
|
||||||
|
.Vt char *
|
||||||
|
type of
|
||||||
|
.Fa state ,
|
||||||
|
the underlying object must be a naturally aligned array of 32-bit values.)
|
||||||
The size of the state array (in bytes) is used by
|
The size of the state array (in bytes) is used by
|
||||||
.Fn initstate
|
.Fn initstate
|
||||||
to decide how sophisticated a random number generator it should use \(em the
|
to decide how sophisticated a random number generator it should use \(em the
|
||||||
@@ -127,26 +125,21 @@ more state, the better the random numbers will be.
|
|||||||
8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
|
8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
|
||||||
the nearest known amount.
|
the nearest known amount.
|
||||||
Using less than 8 bytes will cause an error.)
|
Using less than 8 bytes will cause an error.)
|
||||||
The seed for the initialization (which specifies a starting point for
|
The
|
||||||
the random number sequence, and provides for restarting at the same
|
.Fa seed
|
||||||
point) is also an argument.
|
is used as in
|
||||||
|
.Fn srandom .
|
||||||
The
|
The
|
||||||
.Fn initstate
|
.Fn initstate
|
||||||
function
|
function
|
||||||
returns a pointer to the previous state information array.
|
returns a pointer to the previous state information array.
|
||||||
.Pp
|
.Pp
|
||||||
Once a state has been initialized, the
|
|
||||||
.Fn setstate
|
|
||||||
routine provides for rapid switching between states.
|
|
||||||
The
|
The
|
||||||
.Fn setstate
|
.Fn setstate
|
||||||
function
|
routine switches
|
||||||
returns a pointer to the previous state array; its
|
.Fn random
|
||||||
argument state array is used for further random number generation
|
to using the provided state.
|
||||||
until the next call to
|
It returns a pointer to the previous state.
|
||||||
.Fn initstate
|
|
||||||
or
|
|
||||||
.Fn setstate .
|
|
||||||
.Pp
|
.Pp
|
||||||
Once a state array has been initialized, it may be restarted at a
|
Once a state array has been initialized, it may be restarted at a
|
||||||
different point either by calling
|
different point either by calling
|
||||||
|
|||||||
Reference in New Issue
Block a user