From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Keith Wright Newsgroups: gmane.lisp.guile.user Subject: Re: Generating "independent" random numbers Date: Wed, 04 Oct 2023 12:14:06 -0400 Message-ID: <87fs2qnz5d.fsf@free-comp-shop.com> References: <34c4e0da-34fa-4212-8d1f-060a809b08a0@posteo.de> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="37872"; mail-complaints-to="usenet@ciao.gmane.io" Cc: maximedevos@telenet.be, guile-user@gnu.org To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Oct 04 18:14:59 2023 Return-path: Envelope-to: guile-user@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 1qo4WX-0009TV-Nu for guile-user@m.gmane-mx.org; Wed, 04 Oct 2023 18:14:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo4W3-0005jN-Da; Wed, 04 Oct 2023 12:14:27 -0400 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 1qo4Vs-0005iY-1U for guile-user@gnu.org; Wed, 04 Oct 2023 12:14:17 -0400 Original-Received: from fcx1.keithdiane.us ([209.222.4.146]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qo4Vo-0001hO-4P for guile-user@gnu.org; Wed, 04 Oct 2023 12:14:14 -0400 Original-Received: from fcx1 (fcx1.keithdiane.us [209.222.4.146]) by fcx1.localdomain (Postfix) with ESMTP id 09091679; Wed, 4 Oct 2023 12:14:07 -0400 (EDT) In-Reply-To: <34c4e0da-34fa-4212-8d1f-060a809b08a0@posteo.de> (message from Zelphir Kaltstahl on Tue, 3 Oct 2023 22:22:09 +0000) Received-SPF: none client-ip=209.222.4.146; envelope-from=kwright@keithdiane.us; helo=fcx1.keithdiane.us X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19228 Archived-At: From: Zelphir Kaltstahl > my goal is normal distributed floats (leaving aside the finite > nature of the computer and floats). Warning: I am out of my depth, I can't even spell statisticion, but... The following is either provably correct up to round-off, or totally stupid. First define the cumulative distribution for the normal distribution: $$f(x)= \frac{1}{\sqrt{\pi}} \int_{-\infty}^{x} e^{-x^2/2} dx $$ Now to get a normal random variable, let $u$ be a uniform random number on [0,1), then $f^{-1}(u)$ is a standard normal random variable. Computing the inverse of the cumulative normal distribution is left as an exercise, because I don't know how, but it seems possible. From: Maxime Devos > So, to generate an (approximately) uniform random number on [0,1), you > can simply do > > (define (random-real) > (exact->inexact (/ (random N) N))) > > for a suitably large choice of integer N>0. A choice that makes this nice (on a 32 bit machine) is $N = 2^{32}$. -- Keith