summaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/random.3
diff options
context:
space:
mode:
authorAaron Campbell <aaron@cvs.openbsd.org>2000-04-20 13:50:04 +0000
committerAaron Campbell <aaron@cvs.openbsd.org>2000-04-20 13:50:04 +0000
commitba6b056376adedc82f4ac0f41b5eed2fa3f30c75 (patch)
treee5c095a3d4f9afb3b98cca651e27f12c8880ffbd /lib/libc/stdlib/random.3
parent51643f419480d5bdfbed4ef6c16cf20340d8a357 (diff)
Flesh out stdlib function man pages.
Diffstat (limited to 'lib/libc/stdlib/random.3')
-rw-r--r--lib/libc/stdlib/random.339
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3
index 260c2398164..d3a3198ebfb 100644
--- a/lib/libc/stdlib/random.3
+++ b/lib/libc/stdlib/random.3
@@ -29,7 +29,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: random.3,v 1.11 2000/04/03 23:23:48 millert Exp $
+.\" $OpenBSD: random.3,v 1.12 2000/04/20 13:50:02 aaron Exp $
.\"
.Dd April 19, 1991
.Dt RANDOM 3
@@ -56,23 +56,27 @@
.Sh DESCRIPTION
The
.Fn random
-function
-uses a non-linear additive feedback random number generator employing a
-default table of size 31 long integers to return successive pseudo-random
+function uses a non-linear additive feedback random number generator employing
+a default table of size 31 long integers to return successive pseudo-random
numbers in the range from 0 to (2**31)\-1.
The period of this random number generator is very large, approximately
16*((2**31)\-1.
.Pp
The
-.Fn random Ns / Fn srandom
-have (almost) the same calling sequence and initialization properties as
+.Fn random
+and
+.Fn srandom
+functions have (almost) the same calling sequence and initialization
+properties as
.Xr rand 3 Ns / Xr srand 3 .
The difference is that
.Xr rand
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 rand 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.
@@ -81,9 +85,10 @@ Unlike
.Xr srand ,
.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
@@ -110,28 +115,28 @@ a fixed seed.
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.
The
.Fn initstate
-function
-returns a pointer to the previous state information array.
+function returns a pointer to the previous state information array.
.Pp
Once a state has been initialized, the
.Fn setstate
routine provides for rapid switching between states.
The
.Fn setstate
-function
-returns a pointer to the previous state array; its
+function returns a pointer to the previous state array; its
argument state array is used for further random number generation
until the next call to
.Fn initstate