United States-English |
|
|
HP-UX Reference > Rrand(3C)HP-UX 11i Version 3: February 2007 |
|
NAMErand(), rand_r(), srand() — simple random-number generator SYNOPSIS#include <stdlib.h> int rand(void); int rand_r(unsigned int *seed); void srand(unsigned int seed); DESCRIPTIONrand() uses a multiplicative, congruential, random-number generator with period 232 that returns successive pseudo-random numbers in the range from 0 to 215-1. srand() can be called at any time to reset the random-number generator to a random starting point. The generator is initially seeded with a value of 1. rand_r() returns a random number at the address pointed to by the randval parameter. The seed parameter can be set at any time to start the random-number generator at an arbitrary point. NoteThe spectral properties of rand() leave a great deal to be desired. drand48() provides a much better, though more elaborate, random-number generator (see drand48(3C)). RETURN VALUEIf seed or randval is NULL, rand_r() returns 0. Otherwise, rand_r() returns a psuedo-random integer. EXAMPLESThe following: int x, y; srand(10); x = rand(); y = rand(); would produce the same results as: int x, y, s = 10; x=rand_r(&s); y=rand_r(&s); |
Printable version | ||
|