6.19.28 rand Function

Generates a pseudo-random number.

Include

<stdlib.h>

Prototype

int rand(void);

Remarks

Successive calls to the rand function generates a pseudo-random number sequence, each number in the range 0 to RAND_MAX.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <stdlib.h>
#inclide <stdio.h>

int main(void)
{
  int value;

  value = rand();
  printf("Today's lucky number is %d\n", value);
}

Example Output

Today's lucky number is 8073