[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SRFI-27, deterministic random generator for floats

From: Zelphir Kaltstahl
Subject: Re: SRFI-27, deterministic random generator for floats
Date: Fri, 29 Sep 2023 09:19:19 +0000

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?


Ah, thank you Jeronimo!

I was under the impression that random-source-make-reals wants the random state 

This apparently work, thank you!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]