Message-Id: <199802041410.QAA04887@ankara.duzen.com.tr> Comments: Authenticated sender is From: "S. M. Halloran" Organization: User RFC 822- and 1123-Compliant To: djgpp AT delorie DOT com Date: Wed, 4 Feb 1998 16:11:26 +0200 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Automatically seeding random numbers In-reply-to: <34D80662.CD7C1FC@ea.oac.uci.edu> Precedence: bulk > Basically, I'd like a program to (automatically) seed srand() with > a > different value each time the program is run. (Currently I require > the user to type in a seed, which is a nuisance.) Initially, I > thought something as simple as srand(clock()) would work, but then I > found out that clock() only returns the number of clock ticks since > the *last* call of clock(), so clock() always returns the value 0 > when called for the first time. Try getting the time of the system clock and use that for a seed. I have done that and the random number list seems to vary. The use of the functions in 'info gcc' (read from RHide) doesn't seem to be very well documented...for example, the time() function. C'est la vie. #include #include func() { time_t sysclock; /* will load # of seconds since 1/1/1970 UTC */ long myrandomnumber; .... time(&sysclock); srandom(sysclock); /* djgpp is using the srandom() function, a contest between Berkeley and AT&T, I think*/ random(); myrandomnumber = random(); /* C library of djgpp also features the rand() function, but cycle differs */ .... } I think there was a thread not too long ago about random() vs. rand(). Check mail archives. Mitch Halloran Research (Bio)chemist Duzen Laboratories Group Ankara TURKEY mitch AT duzen DOT com DOT tr other job title: Sequoia's (dob 12-20-95) daddy