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.