I am trying to get a funtion to return 5 random numbers. Here is my code:
I don't understand why I keep getting the same number returned each time. I call the function 5 times and it just outputs the same number all 5 times. I tried making num a static vairable but it didn't help. I am not sure if I fully understand how function calls work. What I think is happening is the first time I call the function its sets the return value.....which is what it will be when its called again.
#include <ctime> // for srand and rand()
int randGenerator ( void ); // function prototype
int randNum, x,y;
for (x = 0; x <= 5; ++x)
randNum = randGenerator();
std::cout <<randNum <<std::endl;
return 0; // Successful termination
} // End main
int randGenerator( void ) // Fucntion definition
num = 1 + rand() % 13;
How do I make it output a random number each time I call the function?