delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/29/18:05:33

Message-ID: <37A0BAD7.3DB143DB@lycosmail.com>
Date: Thu, 29 Jul 1999 16:34:32 -0400
From: Adam Schrotenboer <ajschrotenboer AT lycosmail DOT com>
X-Mailer: Mozilla 4.6 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: how about "more" random ?
References: <Pine DOT SUN DOT 3 DOT 91 DOT 990729190414 DOT 27831B-100000 AT is>
Reply-To: djgpp AT delorie DOT com


Eli Zaretskii wrote:

> On Thu, 29 Jul 1999, Simon De Deyne wrote:
>
> > Thanks for the answer! I did consider this way, but then,
> > i also noticed that the seeding with the time function  (srand) isn't
> > as random as when i used the other random function.
>
> Seed has nothing to do with randomness.
>
> > > So to produce a random number between 0 and 99
> > > x = rand() % 100;
>
> The low bits of the random numbers are known to be not very random.  If
> you want more random results, try this (untested!):
>
>         x = ((double) rand ()) * 100 / RAND_MAX;

Not exactly the correct method (IIRC), but close:

x = ((double) rand ()/RAND_MAX) * 100;

- Raw text -


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