random number in c++ in range code example
Example 1: random in range c++
v1 = rand() % 100;
v2 = rand() % 100 + 1;
v3 = rand() % 30 + 1985;
Example 2: c++ how to generate a random number in a range
min + ( std::rand() % ( max - min + 1 ) )
Example 3: 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 4: cpp random number in range
int range = max - min + 1;
int num = rand() % range + min;