www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/10/21:00:22

From: "John M. Aldrich" <fighteer AT cs DOT com>
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: <Pine DOT GSO DOT 3 DOT 96 DOT 980410181021 DOT 6181A-100000 AT shell DOT clark DOT net>
NNTP-Posting-Host: ppp214.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 <stdio.h>
#include <stdlib.h>
#include <time.h>

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        |
---------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019