Call function for random amout of times

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.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;

void kafija() {
  cout << "Kafija";
}

void piens() {
  cout << " ar pienu";
}

int main() {
    srand (
        (unsigned) time(0)  
    );
    
	int a = rand()%6+5;
    
    cout << a;
}

sure...
int n = rand()%6+5;
for(int i = 0; i < n; i++)
{
kafija();
}
Thank you so much for the fast answer! Much Love!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#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.

Calling functions is really basic BASIC C++.
https://www.learncpp.com/cpp-tutorial/introduction-to-functions/
Topic archived. No new replies allowed.