From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: fighting djgpp libraries Date: Fri, 10 Apr 1998 20:47:57 -0400 Organization: Two pounds of chaos and a pinch of salt. Lines: 48 Message-ID: <352EBDBD.5C3E@cs.com> References: NNTP-Posting-Host: ppp214.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Jude DaShiell wrote: > > All I was trying to do was to use clock() to seed srandom() since > I think I've maybe figured out a technique for improving random number > generation for programmers using gcc at least. > One thing I noticed was that re-seeding of random number generators > happened very > predictibly in code I've read. > I asked myself would any measureable effect come out of randomizing > re-seeding? It looks like you are trying to reinvent the square wheel. Reseeding the random number generator is not a good way to "randomize" its value; in fact, you should specifically NOT do it! random() is more than capable of generating suitably random sequences without any interference once you seed it initially. Take a look at the source code sometime! The following code is recommended for clean random sequences: #include #include #include int main( void ) { int i; srandom( (int) time( NULL ) ); for ( i = 0; i < 100; i++ ) printf( "%5d ", random( ) % 10000 ); return 0; } Try it. Of course, since time()'s granularity is 1 second, running the program more often than that will generate an identical random sequence, but since you're talking about a game, I hope that won't be a problem. If I'm misinterpreting your intentions, please tell me and I'll try to think of something better. :-) -- --------------------------------------------------------------------- | John M. Aldrich | "It may be better to be a live jackal| | aka Fighteer I | than a dead lion, but it is better | | mailto:fighteer AT cs DOT com | still to be a live lion." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------