Re: Some issues with qrand.
You might want to search through the bug tracker if such an issue is already known. If not, you can create one. Maybe even send in a patch or merge request.
Re: Some issues with qrand.
It seems QtGlobal is not added in online documentation's search tool.
here is the link to report bug:
http://bugreports.qt.nokia.com/secure/Dashboard.jspa
it reqs login.
bala
Re: Some issues with qrand.
Thanks. I've posted two defects about this now:
http://bugreports.qt.nokia.com/browse/QTWEBSITE-109
http://bugreports.qt.nokia.com/browse/QTWEBSITE-110
Added after 7 minutes:
In responce to franz comment:
> Maybe even send in a patch or merge request.
If I were to patch the example then I would need to be absolutely sure I was right. And currently:
- I'm not absolutely sure what this:
QTime::currentTime().elapsed()
should return in the example program - it is always returning 0, but the defect could be in this function which for all I know should be returning something different.
- I've not found anything in the documentation which says that each thread is independant from the point of view of random number generation or not. Thus I could move the seed setting into the 2nd thread and submit that as a code change, but it maybe that it is the wrong thing to do.
Re: Some issues with qrand.
Quote:
Originally Posted by
def
2. In the example application:
http://doc.qt.nokia.com/latest/threa...ustomtype.html
the random seed is set in main() using:
QTime::currentTime().elapsed();
but this is always 0 when I run on windows. Having looked at the documentation I can't see why this is always zero unless the framework calls start() during booting an application - if it does then this example needs changing to use a better seed.
This will always be zero. A temporary QTime object is created and its elapsed() is queried immediately which is bound to be 0 because the time object was never started. It would be much better if the code was substituted with:
or better yet something like:
Code:
qsrand
(QDateTime::currentMSecsSinceEpoch () % 1000000)
In general bear in mind rand() and srand() are quite poor when it comes to generating random numbers and if you really want randomness, you should use some better random number generating algorithm. You can see that even in my last piece of code there is a 1E-6 chance (which is quite high) of getting two identical seeds in a row.
Re: Some issues with qrand.
You could always use QUuid if you really need a unique seed.