a random number generator function in c++ code example
Example 1: c++ generate random numbers
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0));
for (int i = 0; i <= 10; i++)
{
cout << rand() % 10 << " ";
}
}
Example 2: random in c++
v1 = rand() % 100;
v2 = rand() % 100 + 1;
v3 = rand() % 30 + 1985;
Example 3: random numbers c++
#include <random>
std::random_device rd;
std::mt19937 e{rd()};
std::uniform_int_distribution<int> dist{1, 5};
dist(e);
Example 4: random number cpp
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto dist = uniform_int_distribution<int>(l, r);