Mail Archives: djgpp/1998/01/28/20:16:51
Myknees wrote:
>
> I have tried to do random numbers before without success. Now I think I know
> why. In the info documentation's alphabetical list, there is no mention of
> srand(). And there's no cross reference to srand() from rand().
>
[code snipped]
>
> But if this is right, how would a beginner find it out? (Besides, of course,
> reading about it from an outside source.)
srand() was omitted from the documentation, but srandom() was not. I
noticed this, along with several other people, and there is a posted bug
report correcting the docs. In any case, the seed functions probably
ought to be mentioned in the docs for rand() and random(), and I think
this will be done in v2.02.
Your program is very strange. The use of bioskey() for example, is
totally hardware-specific and makes no sense, when all you really need
is getkey() or even getch(). Furthermore, calling srand() once for each
call to rand() doesn't guarantee randomness; in fact it makes the
results less random. You only need to seed a RNG once per program.
As a final note, DJGPP's documentation isn't designed to teach standard
C; it's designed to explain the functionality of the library code. I
can see how it could be made clearer in some cases, but it would be
wasteful to include a complete tutorial on random numbers in the library
documentation when there are entire books devoted specifically to the
subject. :-)
--
---------------------------------------------------------------------
| John M. Aldrich | "Autocracy is based on the assumption|
| aka Fighteer I | that one man is wiser than a million |
| mailto:fighteer AT cs DOT com | men. Let's play that over again, |
| http://www.cs.com/fighteer | too. Who decides?" - Lazarus Long |
---------------------------------------------------------------------
- Raw text -