1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
27 .\" Modified Sun Mar 28 00:25:51 1993, David Metcalfe
28 .\" Modified Sat Jul 24 18:13:39 1993 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified Sun Aug 20 21:47:07 2000, aeb
31 .TH RANDOM 3 2000-08-20 "GNU" "Linux Programmer's Manual"
33 random, srandom, initstate, setstate \- random number generator
36 .B #include <stdlib.h>
38 .B long int random(void);
40 .BI "void srandom(unsigned int " seed );
42 .BI "char *initstate(unsigned int " seed ", char *" state ", size_t " n );
44 .BI "char *setstate(char *" state );
49 function uses a non-linear additive feedback random
50 number generator employing a default table of size 31 long integers to
51 return successive pseudo-random numbers in
52 the range from 0 to \fBRAND_MAX\fR.
53 The period of this random number generator is very large, approximately
58 function sets its argument as the seed for a new
59 sequence of pseudo-random integers to be returned by
61 These sequences are repeatable by calling
65 If no seed value is provided, the
68 is automatically seeded with a value of 1.
72 function allows a state array \fIstate\fP to
73 be initialized for use by
75 The size of the state array
78 to decide how sophisticated a
79 random number generator it should use \(em the larger the state array,
80 the better the random numbers will be.
81 \fIseed\fP is the seed for the
82 initialization, which specifies a starting point for the random number
83 sequence, and provides for restarting at the same point.
87 function changes the state array used by the
90 The state array \fIstate\fP is used for
91 random number generation until the next call to
95 \fIstate\fP must first have been initialized
98 or be the result of a previous call of
103 function returns a value between 0 and
107 function returns no value.
112 functions return a pointer to the previous state
113 array, or NULL on error.
117 A state array of less than 8 bytes was specified to
120 4.3BSD, POSIX.1-2001.
122 Current "optimal" values for the size of the state array \fIn\fP are
123 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to
124 the nearest known amount.
125 Using less than 8 bytes will cause an