X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "MikeC" Newsgroups: comp.os.msdos.djgpp Subject: random() : What am I doing wrong? Lines: 48 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 Message-ID: Date: Thu, 30 Aug 2007 20:47:41 GMT NNTP-Posting-Host: 86.13.154.18 X-Complaints-To: http://netreport.virginmedia.com X-Trace: newsfe7-win.ntli.net 1188506861 86.13.154.18 (Thu, 30 Aug 2007 21:47:41 BST) NNTP-Posting-Date: Thu, 30 Aug 2007 21:47:41 BST Organization: ntl Cablemodem News Service To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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