[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] srfi-27 - producing pseudo and truly random numbers
From: |
Terrence Brannon |
Subject: |
Re: [Chicken-users] srfi-27 - producing pseudo and truly random numbers over a uniform distribution |
Date: |
Mon, 29 Oct 2007 02:46:07 -0400 |
On 10/28/07, Ivan Raikov <address@hidden> wrote:
>
> Hello,
>
> Does the random-mtzig egg do what you need?
It looks better, because you just seed the state as you please and
then consistently pass the state. This means I can have one RNG that
uses the same seed across interpreter invocations and another that is
truly random.
I dont know why things like SRFI-27 get ratified and have the
inconsistency that Kon discusses in the "Issues" section of his docs:
http://www.call-with-current-continuation.org/eggs/srfi-27.html
With your mtzig library, I see how to create a uniformly distributed
real from (0,1)
but I do not see how to create a uniformly distributed integer from
[0,n) where n is some number not necessarily the largest on the
machine.
Also, i do not understand why you did not pass in the created state in
your example at the end:
csi> (require-extension random-mtzig)
csi> (random-mtzig:init! 24)
csi> (random-mtzig:f64vector-randu! 20)
The docs say that N * state (which I assume is a 2-tuple of an integer
and the previously created state) is passed to that function.
In fact, the docs are confusing because the type signatures imply that
the functions take a state, but then the example at the bottom does
not supply a state to random-mtzig:f64vector-randu!
Compare these signatures:
procedure: random-mtzig:init :: [SEED] -> STATE
procedure: random-mtzig:random! :: STATE -> INTEGER
In the first procedure SEED is an optional argument, in the second
STATE is not indicated as optional. It must be supplied.
> It can be seeded from
> /dev/urandom, or with a constant supplied by the user, and you could
> have multiple seed states that are passed to the random number
> generating routines in the egg. I can also add some convenience
> functions, if they would fit your needs better.
Based on your API, here is what I would be aiming for:
(define *fixed-seed* (expt 7 5))
(define fixed-state (random-mtzig:init *fixed-seed*))
(define (roll-fixed n)
(if (zero? n)
(random-mtzig:randu! fixed-state)
(random-mtzig:random-from-zero-to-n n fixed-state) ; [0,n)
))
(define random-state (random-mtzig:init)
(define (roll-random n)
(if (zero? n)
(random-mtzig:randu! random-state)
(random-mtzig:random-from-zero-to-n n random-state) ; [0,n)
))
Re: [Chicken-users] srfi-27 - producing pseudo and truly random numbers over a uniform distribution, Terrence Brannon, 2007/10/29