X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "'" Newsgroups: comp.os.msdos.djgpp Subject: Re: random() : What am I doing wrong? Date: Tue, 04 Sep 2007 12:08:12 -0700 Organization: http://groups.google.com Lines: 55 Message-ID: <1188932892.279559.213990@g4g2000hsf.googlegroups.com> References: NNTP-Posting-Host: 88.153.183.115 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1188932893 23138 127.0.0.1 (4 Sep 2007 19:08:13 GMT) X-Complaints-To: groups-abuse AT google DOT com NNTP-Posting-Date: Tue, 4 Sep 2007 19:08:13 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse AT google DOT com Injection-Info: g4g2000hsf.googlegroups.com; posting-host=88.153.183.115; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Aug 30, 11:47 pm, "MikeC" wrote: > Folks, > > Here's an open invitation to make me feel foolish! > > Here's the program : > > #include > #include > > main() > { long lng; > > lng = rawclock(); > printf("\nClock = %ld - ", lng); > srand(lng); > printf("Random numbers = %ld; %ld; %ld",random(),random(),random()); > > } > > The idea is to seed the random number generator from the clock, so that the > first call to random() will always produce a different result. > > When I run the program several times, here's what it yields : > > Clock = 1392294 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393105 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393314 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393420 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393471 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393512 - Random numbers = 1027100827; 143302914; 2078917053 > Clock = 1393548 - Random numbers = 1027100827; 143302914; 2078917053 > > The 'random' numbers are the same every time I run the program, yet they are > being seeded be a clock value that is different each time. I guess the wood > is there somewhere, but the trees are getting in the way. > > Incidentally, I'm running Windows 2000, SP4. > > Advance thanks, > > MikeC. > -- > Mental decryption required to bamboozle spam robots: > > mike_best$ntlworld*com > $ = @ > * = dot Hi The problem is that srand() work on rand() and not on random(). You have to take srandom() instead srand() and the program will work fine. Moshe