summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/random.3
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/stdlib/random.3')
-rw-r--r--lib/libc/stdlib/random.349
1 files changed, 31 insertions, 18 deletions
diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3
index de1188f2baf..57a2c2b0d94 100644
--- a/lib/libc/stdlib/random.3
+++ b/lib/libc/stdlib/random.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: random.3,v 1.7 1998/02/05 18:50:16 perry Exp $
+.\" $NetBSD: random.3,v 1.8 1998/04/28 21:19:50 fair Exp $
.\"
.\" Copyright (c) 1983, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -46,7 +46,7 @@
.Lb libc
.Sh SYNOPSIS
.Fd #include <stdlib.h>
-.Ft long
+.Ft long
.Fn random void
.Ft void
.Fn srandom "unsigned seed"
@@ -68,46 +68,56 @@ The period of this random number generator is very large, approximately
.if n 16*((2**31)\(mi1).
.Pp
The
-.Fn random Ns / Fn srandom
+.Fn random
+and
+.Fn srandom
have (almost) the same calling sequence and initialization properties as
-.Xr rand 3 Ns / Xr srand 3 .
+.Xr rand 3
+and
+.Xr srand 3 .
The difference is that
-.Xr rand
+.Xr rand 3
produces a much less random sequence \(em in fact, the low dozen bits
-generated by rand go through a cyclic pattern. All the bits generated by
+generated by
+.Xr rand 3
+go through a cyclic pattern.
+All the bits generated by
.Fn random
-are usable. For example,
+are usable.
+For example,
.Sq Li random()&01
-will produce a random binary
-value.
+will produce a random binary value.
.Pp
Unlike
-.Xr srand ,
+.Xr srand 3 ,
.Fn srandom
does not return the old seed; the reason for this is that the amount of
-state information used is much more than a single word. (Two other
-routines are provided to deal with restarting/changing random
-number generators). Like
+state information used is much more than a single word.
+(Two other routines are provided to deal with restarting/changing
+random number generators).
+Like
.Xr rand 3 ,
however,
.Fn random
will by default produce a sequence of numbers that can be duplicated
by calling
.Fn srandom
-with
+with
.Ql 1
as the seed.
.Pp
The
.Fn initstate
routine allows a state array, passed in as an argument, to be initialized
-for future use. The size of the state array (in bytes) is used by
+for future use.
+The size of the state array (in bytes) is used by
.Fn initstate
to decide how sophisticated a random number generator it should use \(em the
more state, the better the random numbers will be.
(Current "optimal" values for the amount of state information are
8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
-the nearest known amount. Using less than 8 bytes will cause an error.)
+the nearest known amount.
+Using less than 8 bytes will cause an error).
The seed for the initialization (which specifies a starting point for
the random number sequence, and provides for restarting at the same
point) is also an argument.
@@ -160,10 +170,13 @@ is called with less than 8 bytes of state information, or if
detects that the state information has been garbled, error
messages are printed on the standard error output.
.Sh SEE ALSO
-.Xr rand 3
+.Xr rand 3 ,
+.Xr srand 3 ,
+.Xr rnd 4 ,
+.Xr rnd 9
.Sh HISTORY
These
-functions appeared in
+functions appeared in
.Bx 4.2 .
.Sh BUGS
About 2/3 the speed of