delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f |
Date: | Wed, 5 Sep 2007 11:11:13 -0400 |
Message-Id: | <200709051511.l85FBDts032068@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: | |
<OFDF9449BD DOT 2DD2DBE4-ON8725734D DOT 005206B1-8725734D DOT 00528A7F AT seagate DOT com> | |
(Gordon DOT Schumacher AT seagate DOT com) | |
Subject: | Re: random() : What am I doing wrong? |
References: | <OFDF9449BD DOT 2DD2DBE4-ON8725734D DOT 005206B1-8725734D DOT 00528A7F AT seagate DOT com> |
Errors-To: | nobody AT delorie DOT com |
> That depends if you care about equidistribution; if you do, you'd be > better off ... not using random() in the first place. > If you do a modulo, you effectively "fold" the original random number > space back on itself - and the numbers will be weighted towards the > first "n" (where n is the remainder of the division). The code above > actually scales the number so you don't have that problem. This has *exactly* the same problem, it just involves different numbers being weighted heavier. If you really want equidistribution, you have to check for the last couple of numbers, and call random() again if you get them.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |