[plt-scheme] Does SRFI-27 specify repeatable PRNGs?

From: Doug Williams (m.douglas.williams at gmail.com)
Date: Wed Jan 2 13:04:08 EST 2008

For example:

(require (lib "27.ss" "srfi"))

(define (random-test n)
  (printf "Random Test~n")
  (do ((i 0 (+ i 1)))
      ((= i n) (void))
    (printf "~a~n" (random-integer 2147483647))))

(random-test 10)

Always gives (when run fresh):

Random Test
883280686
1747413071
1934990987
1651205883
1149373624
816936085
1019268308
797581408
1245017087
332329087

While,

(require (lib "27.ss" "srfi"))

(define (random-test n)
  (printf "Random Test~n")
  (random-source-randomize! default-random-source)
  (do ((i 0 (+ i 1)))
      ((= i n) (void))
    (printf "~a~n" (random-integer 2147483647))))

(random-test 10)

gives different numbers, for example:

Random Test
1470382645
805875569
1100848099
2135863374
1325475753
1919491546
1897091264
429945001
741596119
1171299075

Doug

On Jan 2, 2008 10:54 AM, Doug Williams <m.douglas.williams at gmail.com> wrote:

> Actually, SRFI 27 specifies repeatable random sources.  You have to call
> random-source-randomize! to get different ones.  And, there is a
> random-source-pseudo-randomize! procedure that gives you multiple,
> independent, repeatable random sources.  There are also routines in the
> science collection to create vectors of independent random sources.
>
> Doug
>
>
> On Jan 2, 2008 10:21 AM, Chongkai Zhu <czhu at cs.utah.edu> wrote:
>
> > Erich Rast wrote:
> > > Hi,
> > >
> > > Sorry, I know this is a bit off-topic, but perhaps someone here has
> > > already stumbled across the answer. I'm looking for a good PRNG that
> > > is portable, but it needs to be one that allows me to get exactly the
> > > same PRN sequence from the same seed.
> > >
> > > Can I use SRFI-27 for that purpose or does it only specify the
> > > interface to possibly different PRNGs that might produce different
> > > sequences?
> > >
> >
> > SRFI-27 only specifies the interface to possibly different PRNGs that
> > might produce different sequences. But the reference implementation of
> > SRFI 27 is portable and allows you to get exactly the same PRN sequence
> > from the same seed.
> >
> > > How about the built-in generator of MzScheme, might it change in
> > > future or is it part of the specs that it won't change under the hood?
> > >
> >
> > Matthew just changed the built-in generator of MzScheme, as a result of
> > a discussion here a few days ago. The SRFI 27 implementation in SVN
> > (v399) is build on top of the built-in generator, and produces the same
> > sequence as the reference implementation of SRFI 27.
> >
> > > Best,
> > >
> > > Erich
> > >
> > Chongkai
> >
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080102/6b85ff56/attachment.html>

Posted on the users mailing list.