version 1 showing authors affecting page license.
.
| Rev |
Author |
# |
Line |
| 1 |
perry |
1 |
RANDOM |
| |
|
2 |
!!!RANDOM |
| |
|
3 |
NAME |
| |
|
4 |
SYNOPSIS |
| |
|
5 |
DESCRIPTION |
| |
|
6 |
RETURN VALUE |
| |
|
7 |
ERRORS |
| |
|
8 |
NOTES |
| |
|
9 |
CONFORMING TO |
| |
|
10 |
SEE ALSO |
| |
|
11 |
---- |
| |
|
12 |
!!NAME |
| |
|
13 |
|
| |
|
14 |
|
| |
|
15 |
random, srandom, initstate, setstate - random number generator. |
| |
|
16 |
!!SYNOPSIS |
| |
|
17 |
|
| |
|
18 |
|
| |
|
19 |
__#include |
| |
|
20 |
__ ''seed''__); |
| |
|
21 |
char *initstate(unsigned int__ ''seed''__, char *__''state''__, size_t__ ''n''__); |
| |
|
22 |
char *setstate(char *__''state''__); |
| |
|
23 |
__ |
| |
|
24 |
!!DESCRIPTION |
| |
|
25 |
|
| |
|
26 |
|
| |
|
27 |
The __random()__ function uses a non-linear additive |
| |
|
28 |
feedback random number generator employing a default table |
| |
|
29 |
of size 31 long integers to return successive pseudo-random |
| |
|
30 |
numbers in the range from 0 to __RAND_MAX__. The period |
| |
|
31 |
of this random number generator is very large, approximately |
| |
|
32 |
16*((2**31)-1). |
| |
|
33 |
|
| |
|
34 |
|
| |
|
35 |
The __srandom()__ function sets its argument as the seed |
| |
|
36 |
for a new sequence of pseudo-random integers to be returned |
| |
|
37 |
by __random()__. These sequences are repeatable by |
| |
|
38 |
calling __srandom()__ with the same seed value. If no |
| |
|
39 |
seed value is provided, the __random()__ function is |
| |
|
40 |
automatically seeded with a value of 1. |
| |
|
41 |
|
| |
|
42 |
|
| |
|
43 |
The __initstate()__ function allows a state array |
| |
|
44 |
''state'' to be initialized for use by __random()__. |
| |
|
45 |
The size of the state array ''n'' is used by |
| |
|
46 |
__initstate()__ to decide how sophisticated a random |
| |
|
47 |
number generator it should use -- the larger the state |
| |
|
48 |
array, the better the random numbers will be. ''seed'' is |
| |
|
49 |
the seed for the initialization, which specifies a starting |
| |
|
50 |
point for the random number sequence, and provides for |
| |
|
51 |
restarting at the same point. |
| |
|
52 |
|
| |
|
53 |
|
| |
|
54 |
The __setstate()__ function changes the state array used |
| |
|
55 |
by the __random()__ function. The state array |
| |
|
56 |
''state'' is used for random number generation until the |
| |
|
57 |
next call to __initstate()__ or __setstate()__. |
| |
|
58 |
''state'' must first have been initialized using |
| |
|
59 |
__initstate()__ or be the result of a previous call of |
| |
|
60 |
__setstate()__. |
| |
|
61 |
!!RETURN VALUE |
| |
|
62 |
|
| |
|
63 |
|
| |
|
64 |
The __random()__ function returns a value between 0 and |
| |
|
65 |
RAND_MAX. The __srandom()__ function returns no value. |
| |
|
66 |
The __initstate()__ and __setstate()__ functions |
| |
|
67 |
return a pointer to the previous state array, or NULL on |
| |
|
68 |
error. |
| |
|
69 |
!!ERRORS |
| |
|
70 |
|
| |
|
71 |
|
| |
|
72 |
__EINVAL__ |
| |
|
73 |
|
| |
|
74 |
|
| |
|
75 |
A state array of less than 8 bytes was specified to |
| |
|
76 |
__initstate()__. |
| |
|
77 |
!!NOTES |
| |
|
78 |
|
| |
|
79 |
|
| |
|
80 |
Current |
| |
|
81 |
n'' are 8, 32, 64, 128, and 256 bytes; other |
| |
|
82 |
amounts will be rounded down to the nearest known amount. |
| |
|
83 |
Using less than 8 bytes will cause an error. |
| |
|
84 |
!!CONFORMING TO |
| |
|
85 |
|
| |
|
86 |
|
| |
|
87 |
BSD 4.3 |
| |
|
88 |
!!SEE ALSO |
| |
|
89 |
|
| |
|
90 |
|
| |
|
91 |
rand(3), srand(3) |
| |
|
92 |
---- |