home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12536 < prev    next >
Encoding:
Internet Message Format  |  1992-08-19  |  1.3 KB

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