From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simon Leinen Newsgroups: gmane.emacs.devel Subject: Re: random doesn't feel very random Date: Mon, 27 Aug 2012 08:31:53 +0200 Message-ID: References: <876288yh72.fsf@kanis.fr> <87wr0livd4.fsf@Rainer.invalid> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d04446bfb43830904c8397bce X-Trace: ger.gmane.org 1346049125 17135 80.91.229.3 (27 Aug 2012 06:32:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 27 Aug 2012 06:32:05 +0000 (UTC) Cc: Achim Gratz , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 27 08:32:06 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T5srk-0002aI-Vr for ged-emacs-devel@m.gmane.org; Mon, 27 Aug 2012 08:32:05 +0200 Original-Received: from localhost ([::1]:49961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5srj-0004Fc-1e for ged-emacs-devel@m.gmane.org; Mon, 27 Aug 2012 02:32:03 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:51083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5srg-0004FI-Dc for emacs-devel@gnu.org; Mon, 27 Aug 2012 02:32:01 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T5sra-0001K7-IP for emacs-devel@gnu.org; Mon, 27 Aug 2012 02:32:00 -0400 Original-Received: from mail-ob0-f169.google.com ([209.85.214.169]:48576) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T5sra-0001K2-DC for emacs-devel@gnu.org; Mon, 27 Aug 2012 02:31:54 -0400 Original-Received: by obhx4 with SMTP id x4so8671509obh.0 for ; Sun, 26 Aug 2012 23:31:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=CMArn2F3HMPzCyitezQ5ZpnPK531EX58gMq4mSTbshw=; b=A+nZe0rr7bfSQZ5CV8kmmCbnHlkpxU/Paq6ATlftl4IZypNIcpMRnu3n14gP42ADTd R9TsczkAMHlNf68EaBBWWKSRIQ3L6zeHJ7l1PjcQajTCpieBlKTxd7q8lc+psCw/oBP5 8zF94svUsO60hHwnyejqWh6+qNRMB6f9/BntzJdXvGK0qhHqmUM4GbkoJleM4zLxFR6B 0bMpKUBBBkFz0r+evTBEWTCPJr6S+uLrVoOsbH3g9qdA6zlJRUZ/3cLnNIRtrSHwY8iK Ndm1vOcV+b13oM/IAzspVnNEZMRAXu/UTAWp/7ipooSPyvn1RP2Yzuuo1muhLBkxCll/ jaSA== Original-Received: by 10.182.17.99 with SMTP id n3mr9166712obd.8.1346049113555; Sun, 26 Aug 2012 23:31:53 -0700 (PDT) Original-Received: by 10.182.45.35 with HTTP; Sun, 26 Aug 2012 23:31:53 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.214.169 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152861 Archived-At: --f46d04446bfb43830904c8397bce Content-Type: text/plain; charset=ISO-8859-1 On Mon, Aug 27, 2012 at 2:50 AM, Stefan Monnier wrote: > > Therefore the PRNG should be seeded once at start-up, from a good > > source of entropy. > > IIRC Emacs fails to seed its PRNG at start (IOW it is seeded with > a constant), which is why many packages use (random t). > > So I think the right thing to do now is to do seed it at startup, then > make (random t) a no-op. > > We could consider adding a way to get the PRNG state and reset it later, > but since the PRNG state is Emacs-wide and Emacs is more like an OS than > like an application w.r.t its packages, such an interface would need to > allow several named PRNGs, so you'd call (random N ) to get the next > "random" number from 's stream. What about implementing the Common Lisp conventions for treating PRNG state, i.e. an optional state argument to RANDOM, and a variable *RANDOM-STATE*? Instead of (RANDOM T), people could say something like (SETQ *RANDOM-STATE* (MAKE-RANDOM-STATE T)) if they really want. -- Simon. --f46d04446bfb43830904c8397bce Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Mon, Aug 27, 2012 at 2:50 AM, Stefan Monnier <monnier@iro.umontr= eal.ca> wrote:
> Therefore the PRNG should be seeded once at start-up, from a good
> source of entropy.

IIRC Emacs fails to seed its PRNG at start (IOW it is seeded with
a constant), which is why many packages use (random t).

So I think the right thing to do now is to do seed it at startup, then
make (random t) a no-op.

We could consider adding a way to get the PRNG state and reset it later, but since the PRNG state is Emacs-wide and Emacs is more like an OS than like an application w.r.t its packages, such an interface would need to
allow several named PRNGs, so you'd call (random N <id>) to get t= he next
"random" number from <id>'s stream.
What about implementing the Common Lisp conventions for treati= ng PRNG state, i.e. an optional state argument to RANDOM, and a variable *R= ANDOM-STATE*?=A0
Instead of (RANDOM T), people could say something like (SETQ *RANDOM-S= TATE* (MAKE-RANDOM-STATE T)) if they really want.
--=A0
Simon.
--f46d04446bfb43830904c8397bce--