## mingw-users

 Re: [Mingw-users] Generating random numbers From: David Lucena - 2009-06-06 16:57:17 ``` --- El sáb, 6/6/09, Sylvester Steele escribió: > De: Sylvester Steele > Asunto: [Mingw-users] Generating random numbers > Para: "MinGW Users List" > 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. ```
 Re: [Mingw-users] Generating random numbers From: Tuomo Latto - 2009-06-06 17:12:47 ```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 ```
 Re: [Mingw-users] Generating random numbers From: Greg Chicares - 2009-06-06 23:00:24 ```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. ```