home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / programm / 2311 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  1.6 KB

  1. Path: sparky!uunet!gatech!bloom-beacon!eru.mt.luth.se!lunic!sunic!corax.udac.uu.se!corax.udac.uu.se!pem
  2. From: pem@Minsk.DoCS.UU.SE (Per-Erik Martin)
  3. Newsgroups: comp.programming
  4. Subject: Re: Any simple Random Number generators?
  5. Message-ID: <1992Aug14.104121.29374@corax.udac.uu.se>
  6. Date: 14 Aug 92 10:41:21 GMT
  7. References: <13AUG199218224504@judy.uh.edu>
  8. Sender: news@corax.udac.uu.se
  9. Organization: Student
  10. Lines: 28
  11. In-Reply-To: cscc13@judy.uh.edu's message of Thu, 13 Aug 1992 23:22:00 GMT
  12.  
  13. In article <13AUG199218224504@judy.uh.edu> cscc13@judy.uh.edu (NAVEED IQBAL) writes:
  14.  
  15. >I want to know how random numbers are generated.
  16.  
  17. If you are talking about "pseudo random numbers" (which is the common
  18. case in programming) you may want to read Donald E. Knuth's "The art
  19. of computer programming, vol 2", and definitely the article
  20. "Random number generators: Good ones are hard to find" by Stephen K. Park
  21. and Keith W. Miller in Communications of the ACM October 1988 (v31n10).
  22. This article also contains a proposed "minimal standard" generator which
  23. is simple but yet quite good.
  24.  
  25. >I want to get a "new" random number everytime I run the program.
  26.  
  27. You simply "seed" the generator with the system clock when the program
  28. is started.
  29.  
  30. >I did download a program to do that from wuarchive but I was wondering
  31. >if there was a simpler way.
  32.  
  33. If you're running Unix and C you (usually) have random(3) (good enough)
  34. and drand48(3) (better but slower), and rand(3) *if* it's an ANSI-C
  35. library. (Beware of the old Unix rand()!)
  36.  
  37. --
  38.  |\/|\/|\/| Per-Erik Martin,
  39.  |  |  |/\| Department of Computer Systems, Uppsala University,
  40.  |/\|  |  | Email: pem@minsk.DoCS.UU.SE
  41.