Mail Archives: djgpp/1998/04/10/21:53:55
At 06:19 4/10/1998 -0400, 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 don't understand you here. Why should you want to seed a random number
generator more than once, except to get a predictable sequence of values?
You should seed it once, with something like the time (which, btw, `clock'
does NOT give you).
>I asked myself would any measureable effect come out of randomizing
>re-seeding?
This typically happens already. At least in the simple case of a LCRNG,
calling `random' takes the seed value, does something random to it, returns
it, and stores it back in the seed for the next time. A call to `srandom'
will often `random' several times, to make the values a little less
obviously related to the seed.
>To that end I tried writing the following code. I think it's commented
>pretty well.
>Here's the source code below, I'd like to know how to resolve the
>conflicts;
[snipped]
>#include <stdio.h>
>#include <math.h>
>#include <time.h>
>#include <stdlib.h>
>
>int
>main(void)
> double modf(double x, int *p);
>clock_t
>clock(void);
>long
>random(void);
>{
Why on earth do you re-prototype these functions? They are already
prototyped in the headers, and your redeclaration interferes, hence the errors.
Nate Eldredge
nate AT cartsys DOT com
- Raw text -