I'm new at this so sorry if my vocabulary and stuff is totally off.
With the following syntax, my goal is to call the choose_number function, which, when given two arguments (integers), returns one of those two at random. I run it multiple times with a for loop but it doesn't seem to randomize. Maybe it randomizes the first time, but the other times the loop runs, the value remains the same. Maybe eliminate_door is only being defined once and then that same value is printed over and over again? If you could help me out that would be great.
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int choose_number(int option_a, int option_b)
{
srand(time(0));
int random = rand() % 2;
if (random == 0)
{
return option_a;
}
else
{
return option_b;
}
}
int main()
{
srand(time(0));
int door1 = 1;
int door2 = 2;
int door3 = 3;
for (int i = 1; i <= 300; i++)
{
int eliminate_door = choose_number(door2, door3);
cout << eliminate_door << endl;
}
system ("pause");
return 0;
}