delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/09/05/11:34:50

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Date: Wed, 5 Sep 2007 11:34:39 -0400
Message-Id: <200709051534.l85FYdil032635@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: Gordon DOT Schumacher AT seagate DOT com
CC: djgpp AT delorie DOT com
In-reply-to:
<OF8023CA5C DOT B777E9E3-ON8725734D DOT 00541573-8725734D DOT 00544D8B AT seagate DOT com>
(Gordon DOT Schumacher AT seagate DOT com)
Subject: Re: random() : What am I doing wrong?
References: <OF8023CA5C DOT B777E9E3-ON8725734D DOT 00541573-8725734D DOT 00544D8B AT seagate DOT com>
Errors-To: nobody AT delorie DOT com

> Well, okay - random() doesn't anything like guarantee
> equidistribution.  But that said, wouldn't scaling the result set
> at least not give you anything *worse* than what you started with?

If you do the math, you see that there are 47 numbers left over when
you mod MAX_INT % 50.  That means the last three numbers (47, 48, 49)
are slightly less likely to be chosen.  The difference in probability?
1 in 42,949,672 (0.9999999767169356).

So, for a range this small, it really doesn't matter, and if it *does*
matter, you probably already know more about random number generation
than any of us here.

However, integer modulus is a LOT cheaper than floating point
division.

- Raw text -


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