C++ Standard Library C++ STL Library

C++ <cstdlib> - RAND_MAX constant

The C++ <cstdlib> 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 <cstdlib> header file, it is defined as follows:

#define RAND_MAX /*implementation defined*/             


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

#include <iostream>
#include <cstdlib>

using namespace std;
int main (){
  //displaying the value of RAND_MAX
  cout<<"RAND_MAX = "<<RAND_MAX;
  return 0;

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

RAND_MAX = 2147483647

❮ C++ <cstdlib> Library