emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master d582356: * src/fns.c (Frandom): Handle bignum `limit`s


From: Pip Cet
Subject: Re: master d582356: * src/fns.c (Frandom): Handle bignum `limit`s
Date: Fri, 5 Mar 2021 20:13:40 +0000

On Fri, Mar 5, 2021 at 7:56 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> >> -If @var{limit} is a positive fixnum, the value is chosen to be
> >> +If @var{limit} is a positive integer, the value is chosen to be
> >>  nonnegative and less than @var{limit}.  Otherwise, the value might be
> > Should we add "with every value equally likely" here, or is that
> > perfectly obvious?
>
> We could do that, yes.  While I do understand what's a probability
> distribution, that's about as far as much knowledge goes in this area,
> so I'll let others take care of that.

Some people get philosophical about PRNGs, and they might be upset
about the mere suggestion that 2^N states can be used to generate an
(N+K)-bit pseudo-random integer...

> > That docstring always tricks me into thinking "oh, don't worry about
> > passing something invalid, you'll get an error", when in fact, you get
> > a fixnum. (random -1)? Random fixnum. (random 1.0)? Random fixnum.
> > (random 'many)? Random fixnum.
>
> Yes, this sucks, but I didn't dare to fix it.
> I did fix the negative bignum case, tho: it now signals an error ;-)

But what if someone relied on that?! Let's add a defcustom for it!

> > But I'm really writing to ask whether it might be a good idea to add
> > float support while we're there.
>
> Could be: AFAIK we already have code for it in Calc, so it might be
> a small matter of moving the code.

I'm so glad you didn't suggest cl-random.

> To be honest: I only added support for it because I wanted to write some
> randomized tests for 64bit bindat support and my machine is using 32bit
> pointers still ;-)

Should work for that :-)

> > And, all of this could happen in Lisp, couldn't it? Should it?
>
> You might be right: we should probably export just `get_random` (and the
> seeding part) to ELisp and then write the rest in ELisp.

And then we can get rid of the horror that is cl-random, too, right?

Pip



reply via email to

[Prev in Thread] Current Thread [Next in Thread]