Re: random numbers

Ray Andrews <[email protected]> Mon, 15 Sep 2025 15:05:56 -0700
Newsgroups gmane.comp.shells.zsh.user
Message-ID <[email protected]>
Thanks all:

On 2025-09-15 11:18, Clinton Bunch wrote:
> Also note, RANDOM *isn't* random.  It's a predictable, repeatable 
> sequence of numbers that looks random. No computer produces truly 
> random numbers.  In large part because random is an analog function 
> and computers are inherently digital.  But some sources are better 
> than others.
Sure, I know we can never really 'get there' and I know there are other 
issues with zsh's RANDOM that are well accepted, but the above seemed a 
blatant lack of randomness.

Mark:

> I mean, only if you use the whole value of RANDOM directly, which most 
applications of random numbers don't do. If you do the usual trick of 
taking the remainder of RANDOM modulo a range, e.g. picking 
random digits one at a time with (( RANDOM % 10 )), you won't see such a 
strong weighting. In the case of single digits you are 0.03% less likely 
to get an 8 or 9 than a 0 through 7, but that's a pretty mild deviation 
from uniformity.

Yeah, it's just that this Benford's Law thing only applies to the first 
digit in a set of random data, so the cure would obviate the point of 
the thing.  Anyway it seems that the law doesn't apply to RANDOM data 
anyway as I've since discovered -- I need to research the law a bit 
more.  I'm curious as to the '0.03%' that you mention, why is that?  Or 
is it to complicated to discuss here?

Ditto Roman's fix, it obviates the real issue which is limited to first 
digits.

Lawrence:

> It would be goofy if the shell chose the range of RANDOM just to
eliminate bias with respect to base-10 leading digits.  One could
very well object that such a change would disrupt the current lack
of leading-digit bias for base-8 representations.

That's logical.  Ok then, I'm glad I asked.

> A user who generates and uses random numbers needs to account for
bias.  This is not something the generator can do for you

Right, forewarned is forearmed.  I was frankly expecting to hear that my 
view of randomness is a bit simplistic.   Anyway the result of the 
experiment is a failure in any case -- Benford's Law doesn't work here.