From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jeronimo Pellegrini Newsgroups: gmane.lisp.guile.user Subject: Re: SRFI-27, deterministic random generator for floats Date: Thu, 28 Sep 2023 21:18:28 -0300 Message-ID: <61155c633feda619d67a6e59ecfcd295@aleph0.info> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40948"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Guile User To: Zelphir Kaltstahl Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Sep 29 02:19:29 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 1qm1Dz-000A88-T7 for guile-user@m.gmane-mx.org; Fri, 29 Sep 2023 02:19:28 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qm1DM-0006aj-Mf; Thu, 28 Sep 2023 20:18:40 -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 1qm1DK-0006a6-W4 for guile-user@gnu.org; Thu, 28 Sep 2023 20:18:39 -0400 Original-Received: from mail.aleph0.info ([66.228.54.186] helo=aleph0.info) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qm1DI-0000Mc-MQ for guile-user@gnu.org; Thu, 28 Sep 2023 20:18:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aleph0.info; s=mail; t=1695946708; bh=DzIKIToAvm5J1oYF46CM1ETX418u+k0/xOiBWIDGgoA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qfuGCxathzuJaMEm5XEX/uAIpkh15Z8L+0gchrpFn97HvRkvMUD6xUP5ZrVHUhGR/ +kc2oXJoC65+eGvdwXkSkdJtRpRL6svE+xPHvoGnzLTk44oucXY3IUFQX78lcxczO5 YX8R7c23E3yItgxwuTp/fmcRvo9BvtPttW0Xzm/GqsDpirme6+1VAmDoLp0kKj8iOk 2T2PNKp6JSwk5h9Zje3VWA1IN2d8YEtlX1AMGKEib8wQpz8IXLzw3AtUGgouKKbqbv 5HzbXLNiHGNIxUiP3v4OgEJGcj2qXFXw1SgOlwQQ3i9Cz0bSVaW6wSmxJiDOHLF169 Z2K/mwnXjFHoQ== Original-Received: from localhost (localhost [127.0.0.1]) by aleph0.info (Postfix) with ESMTP id 54C9D42440; Thu, 28 Sep 2023 21:18:28 -0300 (-03) Original-Received: from aleph0.info ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavis, port 10024) with LMTP id PCdXDBOIF6jZ; Thu, 28 Sep 2023 21:18:28 -0300 (-03) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=aleph0.info; s=mail; t=1695946708; bh=DzIKIToAvm5J1oYF46CM1ETX418u+k0/xOiBWIDGgoA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=qfuGCxathzuJaMEm5XEX/uAIpkh15Z8L+0gchrpFn97HvRkvMUD6xUP5ZrVHUhGR/ +kc2oXJoC65+eGvdwXkSkdJtRpRL6svE+xPHvoGnzLTk44oucXY3IUFQX78lcxczO5 YX8R7c23E3yItgxwuTp/fmcRvo9BvtPttW0Xzm/GqsDpirme6+1VAmDoLp0kKj8iOk 2T2PNKp6JSwk5h9Zje3VWA1IN2d8YEtlX1AMGKEib8wQpz8IXLzw3AtUGgouKKbqbv 5HzbXLNiHGNIxUiP3v4OgEJGcj2qXFXw1SgOlwQQ3i9Cz0bSVaW6wSmxJiDOHLF169 Z2K/mwnXjFHoQ== Original-Received: from randomnode.info (localhost [127.0.0.1]) (Authenticated sender: je) by aleph0.info (Postfix) with ESMTPA id 0579B4243F; Thu, 28 Sep 2023 21:18:28 -0300 (-03) In-Reply-To: X-Sender: j_p@aleph0.info Received-SPF: pass client-ip=66.228.54.186; envelope-from=j_p@aleph0.info; helo=aleph0.info X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-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:19205 Archived-At: On 2023-09-28 20:56, Zelphir Kaltstahl wrote: > Hello Guile Users! Hello! > I am trying to deterministically generate random floats using SRFI-27 > and I stumbled upon something weird: > > ~~~~ > (use-modules (srfi srfi-27)) > > (define random-source (make-random-source)) > (define random-state (random-source-pseudo-randomize! random-source 0 > 12345)) > (define random-float-gen (random-source-make-reals random-state)) random-source-make-reals does not accept a random-state, but a random-source (which has an internal random-state, which you already randomized with random-source-pseudo-randomize!) That's why Guile is complaining about a wrong type of argument -- a random-state struct was passed, but a random-source was expected. (By the way, my interpretation of the SRFI is that random-source-pseudo-randomize! changes the internal state of the source passed to it, and it doesn't even need to return anything - Guile seems to do it as a convenience) > > I do not understand, what I am doing wrong, since the same seems to > work for integers: I do (see below). :) > ~~~~ > (use-modules (srfi srfi-27)) > > (define random-source (make-random-source)) > (define random-state (random-source-pseudo-randomize! random-source 0 > 12345)) > (define random-integer-gen (random-source-make-integers random-source)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It works because you got it right this time (random-source, not random-state). > What do I need to do, to get a deterministic generator like I have for > integers? (define random-float-gen (random-source-make-reals random-source)) ;; <- source, not state Does that fix it? J.