From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: One method for small random nuimbers Date: Mon, 09 Jun 1997 07:54:57 -0400 Organization: Cornell University http://www.cornell.edu Lines: 45 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <339BEF11.BD5@cornell.edu> References: <2 DOT 2 DOT 32 DOT 19970604162434 DOT 0069d50c AT gate> <3395B097 DOT 5077 AT cornell DOT edu> <339830A6 DOT 672 AT blackmagic DOT tait DOT co DOT nz> <3397CBCF DOT 6536 AT pobox DOT oleane DOT com> <339C297F DOT 23A4 AT blackmagic DOT tait DOT co DOT nz> Reply-To: asu1 AT cornell DOT edu NNTP-Posting-Host: cu-dialup-0001.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Bill Currie wrote: > > Francois Charton wrote: > > > > Bill Currie wrote: > > > > > > Basicaly, I treat the number received from the main RNG as a > > > bit stream and pull off the bits as needed. > > > > > I read about such a method being a bad thing in several books > > (Numerical Recipes warns a lot against this, and I remember reading > > something about it in Knuth, I'll dig it out tonight). > > If you can send me a quote, that would be apreciated. > i realize i am not the person to whom this request was directed, but in light of the recent discussions, i think a few quotes can be useful. (you can download chapters from 'merical recipes' at www.std.com/~nr/) Numerical Recipes in C, 2nd ed. p.277: (Linear congruential) generators have their low order (least significant) bits much less random than their high order bits. If you want to generatea random integer between 1 and 10, you should always do it using high order bits as in: j = (int)(10.0*rand()/(RAND_MAX+1.0)); and never by anything resembling j = 1 + (rand() % 10); more related to what bill currie was proposing ("I treat the number received from the main RNG as a bit stream and pull off the bits as needed.") is the remark on p.299, but their warning concerns the opposite of what he wants to do: A word of caution is: Don't use sequential bits from these routines as the bits of a large, supposedly random, integer ... pp.296-300 of their book is devoted to generation of random sequences of bits. -- Sinan