emacs-devel
[Top][All Lists]
Advanced

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

Re: Why have both `random' and `cl-random'?


From: Eli Zaretskii
Subject: Re: Why have both `random' and `cl-random'?
Date: Sat, 10 Feb 2024 11:27:39 +0200

> From: "Alfred M. Szmidt" <ams@gnu.org>
> Cc: emacs-devel@gnu.org
> Date: Sat, 10 Feb 2024 03:10:17 -0500
> 
>    As far as I can tell from the doc strings, the user level funcionality
>    of the two is the same.  If there is a difference, I can't tell it from
>    those doc strings.  But they compute values in different ways
> 
>    If there is no significant user-visible difference, could the two be 
> merged?
> 
> cl-random allows you to specify the seed, while random does not

random does allow to specify the seed:

  random is a built-in function in ‘src/fns.c’.

  (random &optional LIMIT)

  Return a pseudo-random integer.
  By default, return a fixnum; all fixnums are equally likely.
  With positive integer LIMIT, return random integer in interval [0,LIMIT).
  With argument t, set the random number seed from the system’s entropy
  pool if available, otherwise from less-random volatile data such as the time.
  With a string argument, set the seed based on the string’s contents.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> both allow means to limit the value.  Maybe random could be expanded
> to also have the seed?
> 
>  (random &optional LIMIT SEED)
> 
> then cl-random would become a call to (random LIMIT STATE) ...
> 
>    If there is a significant raal user-visible difference, would people please
>    describe it in the doc strings, so a user can decide which one to use?
> 
> The major difference is that one can use cl-random for reproducable
> random numbers, while random cannot.

Yes, because cl-random exposes the state to Lisp, whereas random
doesn't (and is based on implementations some of which don't have any
meaningful state to expose).



reply via email to

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