Lines Matching refs:state

39  * rand()/srand() like interface, this package also has a special state info
43 * that much state information. Good sizes for the amount of state
44 * information are 32, 64, 128, and 256 bytes. The state can be switched by
46 * with initstate(). By default, the package runs with 128 bytes of state
48 * congruential generator. If the amount of state information is less than
51 * Internally, the state information is treated as an array of uint32_t's; the
53 * integer); the remainder of the array is the state information for the
54 * R.N.G. Thus, 32 bytes of state information will give 7 ints worth of
55 * state information, which will allow a degree seven polynomial. (Note:
56 * the zeroeth word of state information also has some other information
62 * the state table will act as a linear feedback shift register, and will
68 * the amount of state information has a vast influence on the period of the
87 * state information and generates far better random numbers than a linear
88 * congruential generator. If the amount of state information is less than
96 * break value on the amount of state information (you need at least this
97 * many bytes of state info to support this random number generator), a degree
145 * element of the state information, which contains info about the current
148 * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3.
162 * fptr and rptr are two pointers into the state info, a front and a rear
164 * cycle cyclically through the state information. (Yes, this does mean we
172 * in the initialization of randtbl) because the state table pointer is set
179 * The following things are the pointer to the state information table, the
182 * of random(), we remember the first location of the state information, not
183 * the zeroeth. Hence it is valid to access state[-1], which is used to
188 static uint32_t *state = &randtbl[1];
222 * type is the trivial no-state-information type, just remember the seed.
223 * Otherwise, initializes state[] based on the given "seed" via a linear
225 * that are exactly rand_sep places apart. Lastly, it cycles the state
235 state[0] = (uint32_t)x;
240 state[i] = good_rand(state[i - 1]);
241 fptr = &state[rand_sep];
242 rptr = &state[0];
258 * value, since the succeeding terms in the state buffer are no longer
269 expected = len = sizeof(state[0]);
271 expected = len = rand_deg * sizeof(state[0]);
275 if (sysctl(mib, 2, state, &len, NULL, 0) == -1 || len != expected) {
286 fptr = &state[rand_sep];
287 rptr = &state[0];
295 * Initialize the state information in the given array of n bytes for future
299 * initialize the state information.
301 * Note that on return from srandom(), we set state[-1] to be the type
306 * Note: the first thing we do is save the current state, if any, just like
309 * Returns a pointer to the old state.
318 char *ostate = (char *)(&state[-1]);
324 state[-1] = rand_type;
326 state[-1] = MAX_TYPES * (rptr - state) + rand_type;
348 state = int_arg_state + 1; /* first location */
349 end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
354 int_arg_state[0] = MAX_TYPES * (rptr - state) + rand_type;
361 * Restore the state from the given state array.
364 * in the current state information, and restore the locations of the pointers
365 * from the old state information. This is done by multiplexing the pointer
366 * location into the zeroeth word of the state information.
369 * setstate() with the same state as the current state.
371 * Returns a pointer to the old state information.
383 char *ostate = (char *)(&state[-1]);
388 state[-1] = rand_type;
390 state[-1] = MAX_TYPES * (rptr - state) + rand_type;
394 state = new_state + 1;
396 rptr = &state[rear];
397 fptr = &state[(rear + rand_sep) % rand_deg];
399 end_ptr = &state[rand_deg]; /* set end_ptr too */
427 i = state[0];
428 state[0] = i = good_rand(i);
437 f = state;
441 r = state;