random
Go Up to stdlib.h Index
Header File
stdlib.h
Category
Math Routines
Prototype
int random(int num);
Description
Random number generator.
random returns a random number between 0 and abs(num-1). random(num) is a macro defined in stdlib.h. Both num and the random number returned are integers with a maximum value of LRAND_MAX.
Return Value
random returns a number between 0 and (num-1).
Example
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
/* prints a random number in the range 0 to 99 */
int main(void)
{
randomize();
printf("Random number in the 0-99 range: %d\n", random (100));
return 0;
}
Portability
| POSIX | Win32 | ANSI C | ANSI C++ |
|---|---|---|---|
|
+ |