Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] zsh/random module [UPDATED]



Daniel Shahaf wrote on Wed, 23 Nov 2022 23:54 +00:00:
> dana wrote on Wed, 23 Nov 2022 21:42 +00:00:
>> On Wed 23 Nov 2022, at 13:46, Daniel Shahaf wrote:
>>> Oh, and bump that 16 to something 3 or 4 times as big, because a 1/65536
>>> chance isn't really enough in a world where automated builds (CI,
>>> distros' QA, etc.) is a thing.
>>
>> I feel like it should be very nearly impossible for a test to fail just for
>> randomness reasons. Maybe it's over-kill but in my draft reply to the patch i
>> was going to suggest something like this:
>>
>>   () {
>>     repeat $(( 10 ** 5 )); do
>>       getrandom -L4 -U5 -c64 -a tmpa
>>       [[ $tmpa[(r)5] == 5 ]] && return 0
>>     done
>>     return 1
>>   }
>>
>
> No maybe about it :)
>
> With these parameters, the probability of a false positive is 2 to the
> power of minus the overall number of iterations, i.e., 2**(-6.4 million),
> which is 1/[a number that has 1.9M decimal digits].
>
> To be clear, it's not 1/1.9M, which is about the probability of a random
> Londoner being at 10 Downing Street right now.  It's 1/[10 ** 1.9M],
> which is about the probability of correctly guessing the genders of all
> Londoners.

To be clear, I don't mean guessing the gender /ratio/.  I mean filling
a spreadsheet with one row for each Londoner and having to guess each and
every row correctly, without any information about the particular Londoner.

> If you converted the entire Earth's mass to CPUs and ran «getrandom -L4
> -U5 -c64» on it repeatedly until Sol died, and the CPUs all operated at
> 4GHz, and there were no bugs in anything, the chance of getting a single
> run to not return a 5 would still be something like a billion to one
> (give or take several zeroes depending on CPU mass, the argument to -c,
> and so on).
>
> That's why in practice, if a single -c64 call ever doesn't return a 5,
> it's safe to assume there's a bug.
>
> Conversely, if you actually retain those 6.4 million iterations, what's
> the probability that the outer loop will return 0 on the first iteration
> and then a gamma ray will flip that to 0?




Messages sorted by: Reverse Date, Date, Thread, Author