From: eheft AT dnaco DOT net (Eric Heft) Newsgroups: comp.os.msdos.djgpp Subject: Re: Random generator? Date: 2 May 1997 20:11:10 GMT Organization: The Dayton Network Access Company (DNACo) Lines: 32 Message-ID: <5kdhou$o9r$1@pike.dnaco.net> References: <2 DOT 2 DOT 32 DOT 19970429193847 DOT 006a0ec4 AT gate72> <33665CFB DOT C26 AT cs DOT com> NNTP-Posting-Host: kirk.dnaco.net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On getting random numbers : If you do a histogram of rand() % 100 or random() % 100 you will find that its not uniform. If you image that rand return a uniform number from 0-31 and you % 10 you map [ rand val ] -> (val % 10) [0,10,20,30] -> 0 [1,11,21,31] -> 1 [2,12,22] -> 2 [3,13,23] -> 3 [4,14,24] -> 4 . . . . [9,19,29] -> 9 Depending on what your doing it may be close enough not to matter. Somthing like this gets rid of this problem. int rnd(int lo,int hi) { int rng = hi - lo + 1; return ( lo + rng * rand() / MAX_INT ); } I only spent a couple days trying to find why a modeler I was writing always favored low number 8^)