Generating random numbers

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating random numbers

Sylvester Steele
Hi,

I need to generate a large number of random numbers. The normal rand function that mingw supports generates numbers only till 32767- ie it can give me at most 32767 random numbers. I'll need random numbers in the range of say 5 million. I have not been able to find any built in function that does this on msdn etc. I've read on forums that this is compiler dependent and can't be changed. I can of course write my own routine to generate random numbers, but before I do this I'd like to know if there is another existing way of generating random numbers that would fit my requirements. Any pointers would be helpful.

Thanks a lot,
Sylvester

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Generating random numbers

Greg Chicares
On 2009-06-06 12:48Z, Sylvester Steele wrote:
>
> I need to generate a large number of random numbers. The normal rand
> function that mingw supports generates numbers only till 32767- ie it can
> give me at most 32767 random numbers. I'll need random numbers in the range
> of say 5 million. I have not been able to find any built in function that
> does this on msdn etc. I've read on forums that this is compiler dependent
> and can't be changed. I can of course write my own routine to generate
> random numbers, but before I do this I'd like to know if there is another
> existing way of generating random numbers that would fit my requirements.

See the links given here:
  http://article.gmane.org/gmane.comp.gnu.mingw.user/19661

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Generating random numbers

David Lucena
In reply to this post by Sylvester Steele



--- El sáb, 6/6/09, Sylvester Steele <[hidden email]> escribió:

> De: Sylvester Steele <[hidden email]>
> Asunto: [Mingw-users] Generating random numbers
> Para: "MinGW Users List" <[hidden email]>
> Fecha: sábado, 6 junio, 2009 2:48
> Hi,
>
> I need to generate a large number of random numbers. The
> normal rand function that mingw supports generates numbers
> only till 32767- ie it can give me at most 32767 random
> numbers. I'll need random numbers in the range of say 5
> million. I have not been able to find any built in function
> that does this on msdn etc. I've read on forums that
> this is compiler dependent and can't be changed. I can
> of course write my own routine to generate random numbers,
> but before I do this I'd like to know if there is
> another existing way of generating random numbers that would
> fit my requirements. Any pointers would be helpful.
>
>

A simple idea could be generating two or three random numbers and multiply them.


     

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Generating random numbers

Tuomo Latto
David Lucena wrote:

>> I need to generate a large number of random numbers. The
>> normal rand function that mingw supports generates numbers
>> only till 32767- ie it can give me at most 32767 random
>> numbers. I'll need random numbers in the range of say 5
>> million. I have not been able to find any built in function
>> that does this on msdn etc. I've read on forums that
>> this is compiler dependent and can't be changed. I can
>> of course write my own routine to generate random numbers,
>> but before I do this I'd like to know if there is
>> another existing way of generating random numbers that would
>> fit my requirements. Any pointers would be helpful.
>
> A simple idea could be generating two or three random numbers and multiply them.

I think that would seriously warp the distribution.
Bit-shifting (and possibly XORing) would be better.
Or you could use the bits for a mantissa and exponent
of a floating point number.
Which, I suppose, brings us to quality issues, etc.


--
Tuomo

... A chicken is an egg's way of producing more eggs


------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: Generating random numbers

Greg Chicares
On 2009-06-06 17:11Z, Tuomo Latto wrote:

> David Lucena wrote:
>>> I need to generate a large number of random numbers. The
>>> normal rand function that mingw supports generates numbers
>>> only till 32767- ie it can give me at most 32767 random
>>> numbers. I'll need random numbers in the range of say 5
>>> million. I have not been able to find any built in function
>>> that does this on msdn etc. I've read on forums that
>>> this is compiler dependent and can't be changed. I can
>>> of course write my own routine to generate random numbers,
>>> but before I do this I'd like to know if there is
>>> another existing way of generating random numbers that would
>>> fit my requirements. Any pointers would be helpful.
>>
>> A simple idea could be generating two or three random numbers and multiply them.
>
> I think that would seriously warp the distribution.

For one extreme example of warpage, consider the distribution of
the product of three random boolean values--or the product of
a thousand of them.

> Which, I suppose, brings us to quality issues, etc.

http://en.wikipedia.org/wiki/Pseudorandom_number_generator
| Careful mathematical analysis is required to have any confidence a PRNG
| generates numbers that are sufficiently "random" to suit the intended use.
| [An expert] once titled an article, "The generation of random numbers is
| too important to be left to chance."

Fortunately, there's plenty of well-tested free code available.

------------------------------------------------------------------------------
OpenSolaris 2009.06 is a cutting edge operating system for enterprises
looking to deploy the next generation of Solaris that includes the latest
innovations from Sun and the OpenSource community. Download a copy and
enjoy capabilities such as Networking, Storage and Virtualization.
Go to: http://p.sf.net/sfu/opensolaris-get
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users