From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Easy question... Date: Mon, 16 Mar 1998 06:55:54 -0500 Organization: Cornell University (http://www.cornell.edu/) Lines: 27 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <350D1349.53C8C4E6@cornell.edu> References: <19980315154000 DOT KAA08561 AT ladder03 DOT news DOT aol DOT com> <#zHZsoHU9GA DOT 191 AT upnetnews02 DOT moswest DOT msn DOT net> NNTP-Posting-Host: cu-dialup-1227.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 DeHackEd wrote: > > rand() and random() take no arguements. They return numbers from 0 to > RAND_MAX or INT_MAX (not sure which). If you want to limit what they > return, use a mod (rand()%10)command. If you want either 0 or 1, use > random()&0x400 for safety, as random generators are not as random as > one would hope. you don't necessarily have to worry about this if you are just writing a game, but a more proper way of generating a bernoulli (success/fail, coin toss) random variable with probability of success p would be to use #include int bernoulli(double p) { return rand() > p*RAND_MAX; } -- Sinan ---------------------------------------------------------------------- A. Sinan Unur Department of Policy Analysis and Management, College of Human Ecology, Cornell University, Ithaca, NY 14853, USA mailto:sinan DOT unur AT cornell DOT edu http://www.people.cornell.edu/pages/asu1/