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