This question already has an answer here:
I am looking for a simple way how to generate a vector of random integer numbers in a specified range (in my example 0 or 1) in c++. I have looked for possible solutions and implemented the most mentioned one:
vector <short> partition;
for(int i = 0; i < 10; i++)
{
srand( time(NULL) );
int randNum = rand() % 2;
partition.push_back(randNum);
}
However, as I've found later, this approach to generation of random numbers will generate different numbers if and only if it were called only once per second.
I've been searching for a satisfactory solution for a while now, I hope you can help me with this simple looking task.
Aucun commentaire:
Enregistrer un commentaire