delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/04/17:47:54

From: br5an AT aol DOT com (Br5an)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Automatically seeding random numbers
Date: 4 Feb 1998 22:40:15 GMT
Lines: 11
Message-ID: <19980204224001.RAA25173@ladder02.news.aol.com>
NNTP-Posting-Host: ladder02.news.aol.com
Organization: AOL http://www.aol.com
References: <34D80662 DOT CD7C1FC AT ea DOT oac DOT uci DOT edu>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Jason wrote:

<<  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.>>

I think   srand(time(NULL));   might be what your looking for.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019