C Standard Library

C <stdlib.h> - RAND_MAX constant



The C <stdlib.h> RAND_MAX is a macro constant that expands to an integer constant expression whose value is the maximum value returned by the rand function. This value is implementation dependent, but is guaranteed to be at least 32,767 on any standard library implementation.

In the <stdlib.h> header file, it is defined as follows:

#define RAND_MAX /* implementation defined */             

Example:

The example below shows the value of RAND_MAX constant on a given implementation.

#include <stdio.h>
#include <stdlib.h>
 
int main (){
  //displaying the value of RAND_MAX
  printf("RAND_MAX = %d\n", RAND_MAX);
 
  return 0;
}

One of the possible output of the above code could be:

RAND_MAX = 2147483647

❮ C <stdlib.h> Library