rand
raw OCR
Random number generator.
Defined in header <stdlib.h>
Syntax
#include <stdlib.h>
int rand(void);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ | ■ |
Remarks
rand uses a multiplicative congruential random number generator with period Tp- to return successive pseudorandom numbers in the range from
| 0 to RAND_MAX. | The symboHc constant RAND_MAX | is defined in |
stdlib.h; its value is 2^^ - 1.
Return value
rand returns the generated pseudorandom number.
See also
Example
itinclude <stdlib.h>
#include <stdio.h>
int main(void)
{
int i;
printfC'Ten random numbers from 0 to 99\n\n");
for(i=0; i<10; i++)
printf ("%d\n", randO % 100);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/stdlib.h/rand/
· short form /3.1/rand/