diff options
Diffstat (limited to 'src/lib/libc/stdlib/random.3')
-rw-r--r-- | src/lib/libc/stdlib/random.3 | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/lib/libc/stdlib/random.3 b/src/lib/libc/stdlib/random.3 index 260c239816..d3a3198ebf 100644 --- a/src/lib/libc/stdlib/random.3 +++ b/src/lib/libc/stdlib/random.3 | |||
@@ -29,7 +29,7 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" $OpenBSD: random.3,v 1.11 2000/04/03 23:23:48 millert Exp $ | 32 | .\" $OpenBSD: random.3,v 1.12 2000/04/20 13:50:02 aaron Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd April 19, 1991 | 34 | .Dd April 19, 1991 |
35 | .Dt RANDOM 3 | 35 | .Dt RANDOM 3 |
@@ -56,23 +56,27 @@ | |||
56 | .Sh DESCRIPTION | 56 | .Sh DESCRIPTION |
57 | The | 57 | The |
58 | .Fn random | 58 | .Fn random |
59 | function | 59 | function uses a non-linear additive feedback random number generator employing |
60 | uses a non-linear additive feedback random number generator employing a | 60 | a default table of size 31 long integers to return successive pseudo-random |
61 | default table of size 31 long integers to return successive pseudo-random | ||
62 | numbers in the range from 0 to (2**31)\-1. | 61 | numbers in the range from 0 to (2**31)\-1. |
63 | The period of this random number generator is very large, approximately | 62 | The period of this random number generator is very large, approximately |
64 | 16*((2**31)\-1. | 63 | 16*((2**31)\-1. |
65 | .Pp | 64 | .Pp |
66 | The | 65 | The |
67 | .Fn random Ns / Fn srandom | 66 | .Fn random |
68 | have (almost) the same calling sequence and initialization properties as | 67 | and |
68 | .Fn srandom | ||
69 | functions have (almost) the same calling sequence and initialization | ||
70 | properties as | ||
69 | .Xr rand 3 Ns / Xr srand 3 . | 71 | .Xr rand 3 Ns / Xr srand 3 . |
70 | The difference is that | 72 | The difference is that |
71 | .Xr rand | 73 | .Xr rand |
72 | produces a much less random sequence \(em in fact, the low dozen bits | 74 | produces a much less random sequence \(em in fact, the low dozen bits |
73 | generated by rand go through a cyclic pattern. All the bits generated by | 75 | generated by rand go through a cyclic pattern. |
76 | All the bits generated by | ||
74 | .Fn random | 77 | .Fn random |
75 | are usable. For example, | 78 | are usable. |
79 | For example, | ||
76 | .Sq Li random()&01 | 80 | .Sq Li random()&01 |
77 | will produce a random binary | 81 | will produce a random binary |
78 | value. | 82 | value. |
@@ -81,9 +85,10 @@ Unlike | |||
81 | .Xr srand , | 85 | .Xr srand , |
82 | .Fn srandom | 86 | .Fn srandom |
83 | does not return the old seed; the reason for this is that the amount of | 87 | does not return the old seed; the reason for this is that the amount of |
84 | state information used is much more than a single word. (Two other | 88 | state information used is much more than a single word. |
85 | routines are provided to deal with restarting/changing random | 89 | (Two other routines are provided to deal with restarting/changing random |
86 | number generators). Like | 90 | number generators). |
91 | Like | ||
87 | .Xr rand 3 , | 92 | .Xr rand 3 , |
88 | however, | 93 | however, |
89 | .Fn random | 94 | .Fn random |
@@ -110,28 +115,28 @@ a fixed seed. | |||
110 | The | 115 | The |
111 | .Fn initstate | 116 | .Fn initstate |
112 | routine allows a state array, passed in as an argument, to be initialized | 117 | routine allows a state array, passed in as an argument, to be initialized |
113 | for future use. The size of the state array (in bytes) is used by | 118 | for future use. |
119 | The size of the state array (in bytes) is used by | ||
114 | .Fn initstate | 120 | .Fn initstate |
115 | to decide how sophisticated a random number generator it should use \(em the | 121 | to decide how sophisticated a random number generator it should use \(em the |
116 | more state, the better the random numbers will be. | 122 | more state, the better the random numbers will be. |
117 | (Current "optimal" values for the amount of state information are | 123 | (Current "optimal" values for the amount of state information are |
118 | 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to | 124 | 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to |
119 | the nearest known amount. Using less than 8 bytes will cause an error.) | 125 | the nearest known amount. |
126 | Using less than 8 bytes will cause an error.) | ||
120 | The seed for the initialization (which specifies a starting point for | 127 | The seed for the initialization (which specifies a starting point for |
121 | the random number sequence, and provides for restarting at the same | 128 | the random number sequence, and provides for restarting at the same |
122 | point) is also an argument. | 129 | point) is also an argument. |
123 | The | 130 | The |
124 | .Fn initstate | 131 | .Fn initstate |
125 | function | 132 | function returns a pointer to the previous state information array. |
126 | returns a pointer to the previous state information array. | ||
127 | .Pp | 133 | .Pp |
128 | Once a state has been initialized, the | 134 | Once a state has been initialized, the |
129 | .Fn setstate | 135 | .Fn setstate |
130 | routine provides for rapid switching between states. | 136 | routine provides for rapid switching between states. |
131 | The | 137 | The |
132 | .Fn setstate | 138 | .Fn setstate |
133 | function | 139 | function returns a pointer to the previous state array; its |
134 | returns a pointer to the previous state array; its | ||
135 | argument state array is used for further random number generation | 140 | argument state array is used for further random number generation |
136 | until the next call to | 141 | until the next call to |
137 | .Fn initstate | 142 | .Fn initstate |