This question already has an answer here:
- Generating random integer from a range 10 answers
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