home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!sdd.hp.com!usc!rpi!uwm.edu!bionet!agate!linus!linus.mitre.org!truth!jrv
- From: jrv@truth.uucp (Vanzandt)
- Newsgroups: comp.lang.c
- Subject: Re: Scaled random number (Was: Matt Dillon's DICE (Amiga C) and rand() function)
- Message-ID: <1992Aug19.193151.2641@linus.mitre.org>
- Date: 19 Aug 92 19:31:51 GMT
- References: <4476@teslab.lab.oz.au> <1992Aug19.175913.29022@linus.mitre.org>
- Sender: news@linus.mitre.org (News Service)
- Organization: The MITRE Corp., Bedford, Ma.
- Lines: 14
- Nntp-Posting-Host: truth.mitre.org
-
- In article <1992Aug19.175913.29022@linus.mitre.org> jrv@truth.uucp (Vanzandt) writes:
- >In article <4476@teslab.lab.oz.au> andrew@teslab.lab.oz.au (Andrew Phillips) writes:
- >>ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
- >>
- >>: Suppose you want to generate integers in the range 0..N-1,
- >>: with each integer being equally likely, and that you have
- >>: a rand() function which delivers integers in the range 0..RANDMAX
-
- >I believe you must discard the original random
- >number if r/N >= RAND_MAX/N, then you can use r%N or r*N/(RAND_MAX+1).
- ^^^^^^^^^^^^^^^^
- that ought to be r*((unsigned long)N)/((RAND_MAX/N)*N)
-
- - Jim Van Zandt <jrv@mbunix.mitre.org>
-