[Qt-interest] [SOLVED] Re: Best Random Number Generator in Qt

Aaron Lewis aaron.lewis1989 at gmail.com
Fri Apr 16 12:38:49 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/15/2010 08:14 PM, Sean Harmer wrote:
> 
> This is because the random number generator is only a pseudo random number 
> generator. If you do not seed it (or use the same seed) then you get the same 
> sequence of pseudo random numbers each time.
> 
> To get different sequences each time you run your application use the qsrand() 
> function to seed it with a different value each time. A common approach is to 
> seed it with the number of seconds since some time. For example:
> 
> qsrand( QDateTime::currentDateTime().toTime_t() );

Exactly , random seed is always the same , so i got the same number
every time.

> 
> Depending upon your needs though you may wish to use a completely different 
> pseudo random number generator. The last time I checked the built-in ones are 
> not particularly good for serious statistical work (e.g. Monte Carlo 
> simulations). They are fine for simple use cases though.

Right now , using current time as a random seed is good enough.


Thanks Sean ;-)


- -- 
Best Regards,
Aaron Lewis - PGP: 0x4A6D32A0
FingerPrint EA63 26B2 6C52 72EA A4A5 EB6B BDFE 35B0 4A6D 32A0
irc: A4r0n on freenode
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkvIPjkACgkQvf41sEptMqDh1QCeKkeXFSjMTxOeGf+TX6qrEyH1
7v4An3VCWYTanhalbAhuRp9xkpwby4z3
=j2z3
-----END PGP SIGNATURE-----



More information about the Qt-interest-old mailing list