Random numbers in Qt
Unsolved
General and Desktop
-
Hi! I want random number for a few thousands numbers range, but i dont know how to do it.
This is my code and this gives me each program run the same combination of numbers. For example 2,7,5,9... And next time when i run program is the same sequence...int number=tab.size(); //for now size of my array is 1511 random = qrand() % number;
This is code of the same program but in console and it works good.
srand(time(NULL)); random=rand()%tab.size();
It doesnt need to be super perfect random, but although has a different order in each run.
-
Hi! You forgot to initialize the prng. See: void qsrand(uint seed).
-
-
Well... 3 times the same answer :D
-
@SGaist Must be correct then :)
-
I'll give a different answer then, use C++11 random. already thread safe and you can generate random numbers according to different probability distribution:
http://www.cplusplus.com/reference/random/