From: mert0407 AT sable DOT ox DOT ac DOT uk (George Foot) Newsgroups: comp.os.msdos.djgpp Subject: Re: Random numbers Date: 2 Jun 1997 06:34:15 GMT Organization: Oxford University, England Message-ID: <5mtph7$b3v@news.ox.ac.uk> References: <01bc6ce9$72076bc0$363e63c3 AT 8652hvt73761> <5mr4ms$ipp AT freenet-news DOT carleton DOT ca> NNTP-Posting-Host: sable.ox.ac.uk Lines: 44 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Paul Derbyshire (ao950 AT FreeNet DOT Carleton DOT CA) wrote: : For values of x not a power of 2, : random()%x : is not as good as : random()/(MAXINT/x) As it stands, I disagree with this; the integer division MAXINT/x will generally produce rounding errors which could be awkward (you will get numbers which are too large). Performing the entire calucation cast to double, though, can you justify this being a better generator? I remember a thread about this a while ago, and I posted there what I thought was a solution which would produce a fair selection of numbers. I was planning to do some tests on it but never got around to it. My ideal function at the moment: int gfrandom(int range) { int a,b; a=1; while (a=range) b=random()&a; return b; } : Also, there's a name for a thousand million, "billion", which is somewhat : less long and awkward :) Fair enough, but note that in America a billion is 10^9 whereas (certainly in the past) in Britain it is/was 10^12, which is more logical IMHO. I tend to write `thousand million' to remove any ambiguity. I think now `Britain' may sadly have changed to fit the American definition, which I feel is less logical; but we shouldn't be dealing with units of 10^3 anyway... -- George Foot Merton College, Oxford