Re: random numbers

"Mark J. Reed" <[email protected]> Tue, 16 Sep 2025 10:32:50 -0400
Newsgroups gmane.comp.shells.zsh.user
Message-ID <CAA=-s3y0CF030DtoFWdCWjuAb4hOG6h0a5cDgUMw27n+BNiS3g@mail.gmail.com>
On Tue, Sep 16, 2025 at 10:10 Ray Andrews <[email protected]> wrote:

>
> On 2025-09-15 20:10, Lawrence Velázquez wrote:
> > RANDOM % 10 produces the ones digit of the decimal number RANDOM.
> > In the closed interval [0, 32767], each of 0 through 7 occurs as
> > the ones digit in 3277 integers, while 8 and 9 each occurs in 3276
> > integers.
> Thanks.  Not too complicated after all.


Right. In any consecutive range containing a multiple of 10 integers
like [0,32759], each digit shows up in the ones place the same number of
times. The size of the RANDOM range isn't a multiple of 10, though; it has
8 numbers past that, so two digits get left out of the last batch and are
slightly less likely to show up when a random number from the whole range
is taken mod 10. As stated upthread, you can balance this out by simply
rerolling whenever the result of RANDOM is higher than the maximum multiple
of your divisor that fits in the range.

>
> > The uniform distribution doesn't follow Benford's law.
>

Indeed not - Benford's law relies on the fact that real world data is not
uniformly distributed. Even in a uniform range that's not exactly a
multiple of 10, though, the underlying observation that low leading digits
are more likely than high ones still holds.