[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SRFI-27, deterministic random generator for floats
From: |
Zelphir Kaltstahl |
Subject: |
SRFI-27, deterministic random generator for floats |
Date: |
Thu, 28 Sep 2023 23:56:33 +0000 |
Hello Guile Users!
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-float-gen)
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
In procedure struct-vtable: Wrong type argument in position 1 (expecting struct):
#<random-state 7fe21e75abc0>
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
(random-float-gen 5)
;;; <stdin>:11:0: warning: possibly wrong number of arguments to `#<procedure
7f00ce6fb3e0 at srfi/srfi-27.scm:83:5 ()>'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Wrong number of arguments to #<procedure 7f00ce6fb3e0 at srfi/srfi-27.scm:83:5
()>
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
(random-float-gen 0 5)
;;; <stdin>:11:0: warning: possibly wrong number of arguments to `#<procedure
7f00ce6fb3e0 at srfi/srfi-27.scm:83:5 ()>'
ice-9/boot-9.scm:1685:16: In procedure raise-exception:
Wrong number of arguments to #<procedure 7f00ce6fb3e0 at srfi/srfi-27.scm:83:5
()>
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
~~~~
I do not understand, what I am doing wrong, since the same seems to work for
integers:
~~~~
(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))
(random-integer-gen 10)
~~~~
What do I need to do, to get a deterministic generator like I have for integers?
(This is using Guile installed via Guix using the following channels:
~~~~
(list (channel
(name 'guix)
(url"https://git.savannah.gnu.org/git/guix.git")
(branch "master")
(commit
"772eaa69f31457aa19ca4dc4ce755c791d722054")
(introduction
(make-channel-introduction
"9edb3f66fd807b096b48283debdcddccfea34bad"
(openpgp-fingerprint
"BBB0 2DDF 2CEA F6A8 0D1D E643 A2A0 6DF2 A33A 54FA")))))
~~~~
)
Regards,
Zelphir
--
repositories:https://notabug.org/ZelphirKaltstahl
- SRFI-27, deterministic random generator for floats,
Zelphir Kaltstahl <=