jeudi 2 juillet 2015

generate random number in c++ in a range [duplicate]

This question already has an answer here:

i want to generate a random number from a specific rang in each iteration

for (int i=0; i<10;i++)

{
v1[i] = rand() % n;  
}

This code will generate a number between 0 to 9. However I do not want the selected number to be the same as the the index i. For example if I am in the first iteration (ie: i= 1), i want the random number to be either 0,2,3,4,5,6,7,8,9 and not 1 Can some one help me in this ?




Aucun commentaire:

Enregistrer un commentaire