From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Why have both `random' and `cl-random'? Date: Sat, 10 Feb 2024 11:27:39 +0200 Message-ID: <86y1bsu0s4.fsf@gnu.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39614"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, emacs-devel@gnu.org To: "Alfred M. Szmidt" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Feb 10 10:28:50 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rYjfF-000A6S-CH for ged-emacs-devel@m.gmane-mx.org; Sat, 10 Feb 2024 10:28:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rYjeI-0001SL-Hn; Sat, 10 Feb 2024 04:27:50 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYjeG-0001Rq-Pl for emacs-devel@gnu.org; Sat, 10 Feb 2024 04:27:48 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rYjeG-00014c-I1 for emacs-devel@gnu.org; Sat, 10 Feb 2024 04:27:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=YqnCvsL1x2Z5t5nJNARSxEtEjABtqQ+Sy0PITvFQBwQ=; b=OVvIVNAgsEdIExNmOWDa 4t9KFO+YUJhzvIvmHJJVmB44MIdDW3n7MEyqParZ2MQVfcGxDnkA2pfNFcqgal9Nj3nGCsWG3BoyD +9jNAUe3rqnoC9BGn/ILLNJkfjAhRNmku/Lrl93tZ/DMwu0GZ+xXk1aiki0NmyV+MVnjcay0D8qHC SinNGceQzQFwS94LCjleuJqU72AMrCeSR4DZMagBrXiGmrh9Y8/HHq8YDwHJ7IerXhmFA4f2UrekP k2EWihU4nnCbMszvj6/7Ab88p6IF9nvIvEiciE6EFuipQlzLCAYHRLPjCQEodY8k1zHkYiyJ3Eed3 RkoAacWsBEpRSA==; In-Reply-To: (ams@gnu.org) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:316091 Archived-At: > From: "Alfred M. Szmidt" > 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).