Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 8
Set the seed for a pseudo-random number generator
#include <stdlib.h>
void srandom( unsigned int seed );
- seed
- The seed of the sequence of pseudo-random integers.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
|
This function is in libc.a, but not in libc.so
(in order to save space). |
The srandom() function initializes the current state array
using the value of seed.
Use this function in conjunction with the following:
- initstate()
- Initialize the state of the pseudo-random number generator.
- random()
- Generate a pseudo-random number using a default state.
- setstate()
- Specify the state of the pseudo-random number generator.
The random() and srandom() functions have
(almost) the same calling sequence and initialization properties as
rand()
and
srand()
Unlike srand(), srandom() doesn't return
the old seed
because the amount of state information used is much more
than a single word. The initstate() and setstate()
routines are provided to deal
with restarting/changing random number generators. With 256
bytes of state information, the period of the random-number
generator is greater than 269.
Like rand(), random() produces by default a
sequence of numbers that can be duplicated by calling srandom()
with 1 as the seed.
After initialization, a state array can be restarted at a
different point in one of two ways:
- The initstate() function can be used, with the desired
seed, state array, and size of the array.
- The setstate() function, with the desired state, can be
used, followed by srandom() with the desired seed. The
advantage of using both of these functions is that the
size of the state array does not have to be saved once it
is initialized.
POSIX 1003.1 XSI
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
No |
Thread |
No |
drand48(),
initstate(),
rand(),
random(),
setstate(),
srand()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 176
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/srandom.html on line 176