Hi, I would like to ask if its possible to create a random number generator and for the output to be how many times a function is called. I made 2 functions and would like them to be executed as many times, as the RNG number indicates.
examp - RNG spits out 5 - functions kafija() and piens() get called 5 times. If you can help, i would like to keep it as simple as possible.
#include <iostream>
#include <random>
void kafija()
{
std::cout << "Kafija";
}
void piens()
{
std::cout << " ar pienu\n";
}
int main()
{
// let's create a C++ random engine
// seeding it with std::random_device
std::default_random_engine rng(std::random_device{}());
// creating a C++ distribution to create a random
// number between 5 and 10, inclusive
std::uniform_int_distribution<size_t> dis(5, 10);
// generate a random number
size_t num_times { dis(rng) };
// create a loop that runs 5 - 10 times
// using the previously generated random number
for (size_t itr { 0 }; itr < num_times; ++itr)
{
// call the two functions
kafija();
piens();
}
}
Kafija ar pienu
Kafija ar pienu
Kafija ar pienu
Kafija ar pienu
Kafija ar pienu
the output will be different with each run, at least 5 lines displayed, no greater than 10.