Random Numbers in C++

How to return a random number in C++.

Here is a simple function to create a

// Return a random number between 0 and max-1
int randInt(int max) {
  int i = rand()%max;
  return i;
}Code language: JavaScript (javascript)

You can get more information here: https://www.cplusplus.com/reference/cstdlib/rand/

Scroll to Top