home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11821 < prev    next >
Encoding:
Internet Message Format  |  1992-07-31  |  1.1 KB

  1. Path: sparky!uunet!iWarp.intel.com|eff!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: srand() rand() question
  5. Message-ID: <14327@ksr.com>
  6. Date: 31 Jul 92 12:23:42 EDT
  7. References: <1992Jul31.113913.22633@cactus.org>
  8. Sender: news@ksr.com
  9. Distribution: usa
  10. Lines: 14
  11.  
  12. cheselka@cactus.org (Michael R. M. Cheselka) writes:
  13. >  /* What is wrong with this program?  Is it the multiple calls to srand()?
  14. >     rand() is not random at all, and soon duplicates it's self in a repeating
  15. >     pattern.  Is it illegal to repeatedly call srand()? */
  16.  
  17. It is not illegal to repeatedly call srand(), but it also isn't advisable.
  18. Not all seeds are as good as other seeds, so you're rather likely to fall
  19. into one of the short-sequence traps the standard rand() function offers.
  20.  
  21. If you want better random numbers, use the Berkeley random number generator
  22. (source available by ftp, or just grab a copy of Knuth and implement the
  23. random number generator that has a table of 55 numbers and adds elements
  24. separated by some spacing (I forget which algorithm number that is, since
  25. my copy of Knuth isn't handy).
  26.