This question already has an answer here:
- How to generate different random numbers in a loop in C++? 13 answers
Hi I'm trying to generate some random numbers which will be converted to chars later. The problem is the number generated by rand() always return the same although I've used time(0) as the seed for the rand().
int randomNumber(int min, int max)
{
srand(time(0));
int rndm = (rand()%(max-min))+min;
cout<<rndm<<" ";
return 0;
}
Let's say I generate the random 3 times
int main()
{
randomNumber(0,5);
randomNumber(0,5);
randomNumber(0,5);
}
The numbers produced will be 1 1 1 or 2 2 2 etc. Any idea? Thanks