Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: random numbers
On Mon, Sep 15, 2025, at 6:05 PM, Ray Andrews wrote:
> Mark:
>
>> [...] 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.
>
> [...]
>
> I'm curious as to the '0.03%' that you mention, why is that? Or
> is it to complicated to discuss here?
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.
> 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.
The uniform distribution doesn't follow Benford's law.
https://pmc.ncbi.nlm.nih.gov/articles/PMC2866333/#s3
> I was frankly expecting to hear that my view of randomness is
> a bit simplistic.
Probability can be very subtle, and it's hard to be sure you're
doing things right. I'm no expert myself.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author