random number
-
hello friend, why random generator always show same number ?```
for(int j=1;j<s2+1;j++)
{qsrand(time(NULL));
dizi[j]=(qrand()%32);
}
output :
3
3
3
3
or
28
28
28
28 -
hello friend, why random generator always show same number ?```
for(int j=1;j<s2+1;j++)
{qsrand(time(NULL));
dizi[j]=(qrand()%32);
}
output :
3
3
3
3
or
28
28
28
28@veysel.olgun said in random number:
qsrand
You're using deprecated functions. You should rather use http://doc.qt.io/qt-5/qrandomgenerator.html
-
hello friend, why random generator always show same number ?```
for(int j=1;j<s2+1;j++)
{qsrand(time(NULL));
dizi[j]=(qrand()%32);
}
output :
3
3
3
3
or
28
28
28
28@veysel.olgun said in random number:
qsrand(time(NULL));
seeds rand with the
seconds
since the epoch.I would think you end up seeding again in a much quicker time than 1 sec -> next rand is again seeded and calculated the same way -> same "random"-number
-
i understand now , when i write
qsrand(time(NULL)); dizi[j]=(QRandomGenerator::global()->generate()%32);
it works fine
thank you all