Mail Archives: djgpp/1997/06/05/18:09:31
Chris wrote:
>
> Here is a bit of code from C for Dummies. The book is terrible in
> most parts, but this is a nice llittle thing it did. It demonstrates
> how to go about generating random numbers using the computers time.
>
ok, given the reference, it should not be surprising that you do not
know the difference between seeding a random number generator and the
actual algorithm that generates the pseudo-random numbers. a random
number generator is actually a deterministic algorithm. that is, if you
give it the same seed, you will get the same sequence out of it each and
every time. this is actually very desirable for scientific applications.
however, when you are playing a game, you do not want your hero to start
at the same corner all the time. so, seeding the rng eith the ticks
serves the purpose of giving the rng a non-predetermined starting point
every time, and produce a different series every time.
>
> int rnd(int range);
> int seedrnd(void);
what is the point of this? first, your declaration does not match the
actual function. second, why do something that is essentially renaming a
standard library function.
>
> void main(void)
no. int main(void) or int main(int argc, char *argv[]).
> int rnd(int range)
> {
> int r;
> r=rand()%range;
> return(r);
> }
>
the question is whether % preserves the 'statistical randomness' of the
series generated by rand().
this has been answered in detail before. read those posts and, please,
for do not quote any dummies book.
-- Sinan.
- Raw text -