X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Bill Newsgroups: comp.os.msdos.djgpp Subject: Re: random() : What am I doing wrong? Date: Tue, 04 Sep 2007 15:30:36 -0400 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <13drciokqdoav65@corp.supernews.com> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060721 SeaMonkey/1.0.3 MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse AT supernews DOT com Lines: 47 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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. What about if I want to generate numbers in the range of 1 through 50? How do I specify my range? Thanks, Bill