www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/16/20:57:31

Newsgroups: comp.os.msdos.djgpp
From: Butler Owen scm2211 <s9708172 AT tiger DOT vut DOT edu DOT au>
Subject: Re: Random function gives me the same numbers!
In-Reply-To: <357F3A1C.E19378BD@netrover.com>
Message-ID: <Pine.SOL.3.95.980617002819.17603C-100000@tiger.vut.edu.au>
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


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

- Raw text -


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