Subject: Re: bug#75105: (cl-random -1.0e+INF)

From: Pip Cet <[email-masked]>
Date: Mon, 17 Feb 2025 18:26:23 +0000

Mattias Engdegård <[email-masked]> writes:

> 16 feb. 2025 kl. 01.50 skrev Pip Cet <[email-masked]>:
>
>> (cl-random 0.0) returns 0.0, but one could argue it should throw
>
> It definitely should throw, but perhaps it's not worth the
> incompatibility? Not sure, because existing code that passes 0.0 is
> likely buggy anyway.  Or we could say that it's just an ad-hoc
> extension, by vague analogy of (car nil) = nil.

On mathematical grounds, in my humble but correct opinion, the
pseudo-algorithm should be:

1. find a random real number in the closed interval [0, a]
2. round it towards zero.

IOW, that 'a' is never the result is a consequence of the rounding step,
not of using a half-open interval in step 1.

However, Common Lisp disagrees, and the cl- prefix kind of hints we
should heed its opinions.

And using (* x (cl-random 1.0)) if that's what you want seems easy
enough (and, either way, you get bitten by the low precision, with only
8 million possible outcomes).

Will modify the patch accordingly.

Pip