Newsgroups: comp.os.msdos.djgpp From: Butler Owen scm2211 Subject: Re: Random function gives me the same numbers! In-Reply-To: <357F3A1C.E19378BD@netrover.com> Content-Type: TEXT/PLAIN; charset=US-ASCII Message-ID: Sender: news AT matilda DOT vut DOT edu DOT au Organization: Victoria University of Technology References: <357F3A1C DOT E19378BD AT netrover DOT com> Mime-Version: 1.0 Date: Tue, 16 Jun 1998 14:31:19 GMT Lines: 25 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk On Wed, 10 Jun 1998, Nicolas Blais wrote: > Hi, the function below seams to always give me the same set of numbers > in R_C everytime I run it, can it be fixed? > > srandom(clock()/CLOCKS_PER_SEC); AFAIK, clock() returns the number of clocks/ticks/whatever since the program was invoked. This would be the same every run. You would want to use time(NULL); instead, as this will give you the number of seconds since 1 jan 1970 or something. Your not likely to get the same number twice though. Owen Butler > int R_C = random() / (RAND_MAX / 255 + 1); > > Thank you, > Nicolas Blais > > >