From: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
To: Jeronimo Pellegrini <j_p@aleph0.info>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: SRFI-27, deterministic random generator for floats
Date: Fri, 29 Sep 2023 09:19:19 +0000 [thread overview]
Message-ID: <c125e590-fb3a-0e32-7059-4eafc63844d5@posteo.de> (raw)
In-Reply-To: <61155c633feda619d67a6e59ecfcd295@aleph0.info>
On 9/29/23 02:18, Jeronimo Pellegrini wrote:
> On 2023-09-28 20:56, Zelphir Kaltstahl wrote:
>> 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.
Ah, thank you Jeronimo!
I was under the impression that random-source-make-reals wants the random state >.<
This apparently work, thank you!
Regards,
Zelphir
--
repositories: https://notabug.org/ZelphirKaltstahl
prev parent reply other threads:[~2023-09-29 9:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-28 23:56 SRFI-27, deterministic random generator for floats Zelphir Kaltstahl
2023-09-29 0:18 ` Jeronimo Pellegrini
2023-09-29 9:19 ` Zelphir Kaltstahl [this message]
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c125e590-fb3a-0e32-7059-4eafc63844d5@posteo.de \
--to=zelphirkaltstahl@posteo.de \
--cc=guile-user@gnu.org \
--cc=j_p@aleph0.info \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).