unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Why have both `random' and `cl-random'?
@ 2024-02-09  3:49 Richard Stallman
  2024-02-09  6:43 ` Eli Zaretskii
  2024-02-10  8:10 ` Alfred M. Szmidt
  0 siblings, 2 replies; 6+ messages in thread
From: Richard Stallman @ 2024-02-09  3:49 UTC (permalink / raw)
  To: emacs-devel

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

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?

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?

-- 
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why have both `random' and `cl-random'?
  2024-02-09  3:49 Why have both `random' and `cl-random'? Richard Stallman
@ 2024-02-09  6:43 ` Eli Zaretskii
  2024-02-10  8:10 ` Alfred M. Szmidt
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-09  6:43 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

> From: Richard Stallman <rms@gnu.org>
> Date: Thu, 08 Feb 2024 22:49:26 -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

IIUC, the user-level functionality is not the same.  'cl-random'
exposes the state of the RNG, whereas 'random' does not, and is based
on RNG implementations that aren't required to support exposing the
RNG state and setting it.

> 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 doc string of 'cl-random' already says:

  Optional second arg STATE is a random-state object.

We could add to 'cl-random's doc string the description of the
algorithm it uses; however, doing the same for 'random' is not really
possible because its RNG implementation is system-dependent.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why have both `random' and `cl-random'?
  2024-02-09  3:49 Why have both `random' and `cl-random'? Richard Stallman
  2024-02-09  6:43 ` Eli Zaretskii
@ 2024-02-10  8:10 ` Alfred M. Szmidt
  2024-02-10  9:27   ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Alfred M. Szmidt @ 2024-02-10  8:10 UTC (permalink / raw)
  To: rms; +Cc: emacs-devel

   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 --
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.






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why have both `random' and `cl-random'?
  2024-02-10  8:10 ` Alfred M. Szmidt
@ 2024-02-10  9:27   ` Eli Zaretskii
  2024-02-10 15:00     ` Alfred M. Szmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-10  9:27 UTC (permalink / raw)
  To: Alfred M. Szmidt; +Cc: rms, emacs-devel

> 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).



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why have both `random' and `cl-random'?
  2024-02-10  9:27   ` Eli Zaretskii
@ 2024-02-10 15:00     ` Alfred M. Szmidt
  2024-02-10 15:40       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Alfred M. Szmidt @ 2024-02-10 15:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rms, emacs-devel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1104 bytes --]

   >    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.
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Missed that, but doesn't that mean that using a limit _and_ a seed is
not possible?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Why have both `random' and `cl-random'?
  2024-02-10 15:00     ` Alfred M. Szmidt
@ 2024-02-10 15:40       ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-10 15:40 UTC (permalink / raw)
  To: Alfred M. Szmidt; +Cc: rms, emacs-devel

> From: "Alfred M. Szmidt" <ams@gnu.org>
> Cc: rms@gnu.org, emacs-devel@gnu.org
> Date: Sat, 10 Feb 2024 10:00:39 -0500
> 
>      (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.
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Missed that, but doesn't that mean that using a limit _and_ a seed is
> not possible?

I think the idea in that case is that you first call random with a
seed (and ignore the value), and then continue calling it with a
limit.  But I didn't try that, so maybe I'm missing something.



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-10 15:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-09  3:49 Why have both `random' and `cl-random'? Richard Stallman
2024-02-09  6:43 ` Eli Zaretskii
2024-02-10  8:10 ` Alfred M. Szmidt
2024-02-10  9:27   ` Eli Zaretskii
2024-02-10 15:00     ` Alfred M. Szmidt
2024-02-10 15:40       ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).