Mail Archives: djgpp/1998/09/22/19:49:33
Paul Minerva wrote:
>
> I am writing an application that needs the rand() function. When I compile
> this program using the UNIX g++ it works fine. When I compile the program
> using gcc, it does not seem to work correctly.
> Any idea what the problem is?
First, please post text attachments as text, not uuencoded.
You don't say how it works incorrectly, but perhaps you mean the fact
that it produces the same numbers every time. This is because you
aren't seeding the random number generator. The numbers are actually
generated as a series based on some initial value, and that value is the
seed. You set it with `srand', typically once at the beginning of your
program. The return value of `time(0)' is a good value to use.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -