generate random number in range c++ code example
Example 1: random in range c++
v1 = rand() % 100;
v2 = rand() % 100 + 1;
v3 = rand() % 30 + 1985;
Example 2: c rand range
rand() % (max_number + 1 - minimum_number) + minimum_number
Example 3: c++ how to generate a random number in a range
min + ( std::rand() % ( max - min + 1 ) )
Example 4: c++ generate random numbers in range
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
for (int i = 0; i <= 10; i++)
{
int start = 3;
int end = 8;
cout << start + rand() % (end - start + 1);
}
}
Example 5: cpp random number in range
int range = max - min + 1;
int num = rand() % range + min;