Qrand() is this just a wrapper for rand()? Does it have the same limitations?
-
wrote on 12 Oct 2012, 03:47 last edited by
I couldn't find a page that talked about qrand() or sqrand() . So I'm asking here if it just wraps the functions and has same limitations?
For example srand() and rand() will always product the same numbers given the same seed. Also it only has 0 - RAND_MAX ( which is usually around 35k)
Which makes it a rather poor random number generator without some extra work, like building a larger value out of just the first byte of the int returned by rand. But that's another story.
Is there any other options in QT? If not I'll just do what I said above and build larger data types out of the values returned.
-
wrote on 12 Oct 2012, 04:30 last edited by
The limitations are the same. The only difference between qrand() and standard rand() is thread safety. You'll have to find some C++ lib elsewhere if you want a better random number generator. Just search the Web, there are actually quite many.
-
wrote on 12 Oct 2012, 10:06 last edited by
Take a look at boost::random, its header only and gives you several options for generating random numbers.
-
wrote on 12 Oct 2012, 11:08 last edited by
You want the generated random numbers to be always different ?
You can use time function to seed random number generator and then generates the random number@
srand((unsigned)time(NULL));
int d=rand();
cout<<d;
@The time is a double edged sword :)
3/4