[Qt-interest] Best Random Number Generator in Qt

Denis Akhmetzyanov dakhmetzyanov at smartlabs.tv
Thu Apr 15 15:11:48 CEST 2010


Hi, Tony
You are right. Of course (max + 1).


2010/4/15 Tony Rietwyk <tony.rietwyk at rightsoft.com.au>

>  Hi Denis,
>
> Aaron said he needs 0 to max, so he will have to use  "return qrand() %
> (max + 1);"
>
> Regards,
>
>
>  -----Original Message-----
> *From:* qt-interest-bounces at trolltech.com [mailto:
> qt-interest-bounces at trolltech.com] *On Behalf Of *Denis Akhmetzyanov
> *Sent:* Thursday, 15 April 2010 22:16
> *To:* Aaron Lewis
> *Cc:* qt-interest at trolltech.com
> *Subject:* Re: [Qt-interest] Best Random Number Generator in Qt
>
> You could use:
>
> int mpainter::getRandomNumber(int max)
> {
> return qrand() % max;
> }
>
>
> 2010/4/15 Aaron Lewis <aaron.lewis1989 at gmail.com>
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi,
>> For example , i'd like to get a integer range from 0 to max , i can use
>> such a function:
>>
>> int mpainter::getRandomNumber(int max)
>> {
>> return double(qrand()) / RAND_MAX * max;
>> }
>>
>> But i don't think this is a good way to generate it , i always got a
>> number two.
>>
>> Is there any good method to generate random number in range ?
>>
>> Appreciate any of your help ;-)
>>
>> - --
>> 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/
>>
>> iEYEARECAAYFAkvHAQ8ACgkQvf41sEptMqDEIgCfZYyF2NIR3sEr+/ldA5vSWVxt
>> 84EAnibCo5O54pDnw5W3EY0E5hPWTXL5
>> =SrC/
>> -----END PGP SIGNATURE-----
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>
>
>
> --
> Best regards,
> Denis Akhmetzyanov
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.801 / Virus Database: 271.1.1/2811 - Release Date: 04/15/10
> 04:31:00
>
>


-- 
Best regards,
Denis Akhmetzyanov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100415/56bd1d30/attachment.html 


More information about the Qt-interest-old mailing list