Sender: nate AT cartsys DOT com Message-ID: <360835F0.4750F448@cartsys.com> Date: Tue, 22 Sep 1998 16:42:40 -0700 From: Nate Eldredge MIME-Version: 1.0 To: Paul Minerva CC: djgpp AT delorie DOT com Subject: Re: problem with rand() References: <000301bde661$b7465d20$fd8f2499 AT Internet DOT usinet DOT pminerv> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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