GNU bug report logs -
#75105
(cl-random -1.0e+INF)
Previous Next
Full log
Message #22 received at submit <at> debbugs.gnu.org (full text, mbox):
Mattias EngdegÄrd <mattias.engdegard <at> gmail.com> writes:
> 16 feb. 2025 kl. 01.50 skrev Pip Cet <pipcet <at> protonmail.com>:
>
>> (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
This bug report was last modified 116 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.