c++ random number generator srandom code example
Example 1: c++ random
#include <cstdlib>
#include <iostream>
#include <ctime>
int main()
{
std::srand(std::time(nullptr)); // use current time as seed for random generator
int random_variable = std::rand();
std::cout << "Random value on [0 " << RAND_MAX << "]: "
<< random_variable << '\n';
}
Example 2: random number cpp
// Add thus to with the headers
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// Generate a function that will give values between l and r inclusive
auto dist = uniform_int_distribution<int>(l, r);
// get the random number using dist(rng);