Mail Archives: djgpp/1998/09/22/22:15:27
From: | Erik Max Francis <max AT alcyone DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: problem with rand()
|
Date: | Tue, 22 Sep 1998 18:48:26 -0700
|
Organization: | Alcyone Systems
|
Lines: | 31
|
Message-ID: | <3608536A.2377DAA0@alcyone.com>
|
References: | <000301bde661$b7465d20$fd8f2499 AT Internet DOT usinet DOT pminerv>
|
NNTP-Posting-Host: | charmaine.alcyone.com
|
Mime-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
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.
You could stand to be more specific about how it doesn't "work
correctly."
> Any idea what the problem is?
For one thing, you're not seeding the random number generator, which you
have to do if you want unique sequences.
Before your first call to rand, call
srand(time(0));
to seed the random number generator. Be sure to #include <time.h>
before the use so the compiler knows the prototype for time.
--
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900
Alcyone Systems / irc maxxon (efnet) / finger max AT sade DOT alcyone DOT com
San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
\
/ Melancholy men, of all others, are the most witty.
/ Aristotle
- Raw text -