I am trying to generate the Random Number between the range of 0 to 4000 and for the loop of aprroximately 300 times. I am getting some how a duplicate result if I try to to generate it time and again. Is there any better logic than mine please share , below is my code with which I am generating the Random Numbers :-
srand(time(0));
randnum1[0] =0;
for(int x=1;x<300;x++)
{
randnum1[x] = rand()%4000;
std::sort(randnum1.begin(), randnum1.end());
if (randnum1[x] == 0 || std::abs(randnum1[x] - randnum1[x-1]) <= 16)
randnum1[x] += 16 ;
}
Aucun commentaire:
Enregistrer un commentaire