From: Eli Zaretskii <eliz@gnu.org>
To: "Alfred M. Szmidt" <ams@gnu.org>
Cc: rms@gnu.org, emacs-devel@gnu.org
Subject: Re: Why have both `random' and `cl-random'?
Date: Sat, 10 Feb 2024 11:27:39 +0200 [thread overview]
Message-ID: <86y1bsu0s4.fsf@gnu.org> (raw)
In-Reply-To: <E1rYiRF-0005MS-Aa@fencepost.gnu.org> (ams@gnu.org)
> 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).
next prev parent reply other threads:[~2024-02-10 9:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2024-02-10 15:00 ` Alfred M. Szmidt
2024-02-10 15:40 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86y1bsu0s4.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=ams@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=rms@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.