lundi 23 mai 2016

Calling random function inside another function

I have function which genrenate me random index like this :

size_t randomIndex(vector<int>myVector) {
    srand(time(NULL));
    size_t index1 = rand() % myVector.size();
    return index1; 
}

I call it inside another funtion :

void generaTwoIndex(vector<int> myVector2) {
     size_t index1 = randomIndex(myVector2); 
     cout << "index1 = " << index1 << endl; 
     size_t index2 = randomIndex(myVector2);
     cout << "index2 = " << index2 << endl;
}

It generate me the same index. What is the issue ? Thank's in advance for your answers.




Aucun commentaire:

Enregistrer un commentaire