I suggest to use the current-pseudo-random-generator, because otherwise the
shuffle/seed will change globally the random sequence of all the program.
For example:

;---
#lang racket

;; shuffle/seed : list? integer -> list?
(define (shuffle/seed lst seed)
  (random-seed seed)
  (shuffle lst))

(define a-list (list 1 2 3 4 5 6 7 8 9 10))

(shuffle/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.5029567011201275
(shuffle/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.5029567011201275
(shuffle/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.1591727701267079
(shuffle/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.1591727701267079

(define (shuffle/temp/seed lst seed)
  (parameterize ([current-pseudo-random-generator
(make-pseudo-random-generator)])
    (random-seed seed)
    (shuffle lst)))

(shuffle/temp/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.9636171831359096 (may change)
(shuffle/temp/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.6541579154005383 (may change)
(shuffle/temp/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.679958229286436  (may change)
(shuffle/temp/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.22302974490220356 (may change)
;---

[Note: shuffle/temp/seed is a horrible name. I used a different name to
avoid confusion.]

Gustavo



On Fri, Dec 2, 2016 at 5:37 AM, <meino.cra...@gmx.de> wrote:

> Daniel Feltey <dfel...@ccs.neu.edu> [16-12-02 09:28]:
> > I think something like this works:
> >
> > ;; shuffle/seed : list? integer -> list?
> > (define (shuffle/seed lst seed)
> >   (random-seed seed)
> >   (shuffle lst))
> >
> > > (define a-list (list 1 2 3 4 5 6 7 8 9 10))
> > > (shuffle/seed a-list 0)
> > '(3 4 9 8 5 1 10 7 6 2)
> > > (shuffle/seed a-list 0)
> > '(3 4 9 8 5 1 10 7 6 2)
> > > (shuffle/seed a-list 1)
> > '(3 2 1 8 5 10 4 7 6 9)
> > > (shuffle/seed a-list 1)
> > '(3 2 1 8 5 10 4 7 6 9)
> >
> >
> >
> > On Fri, Dec 2, 2016 at 2:05 AM, <meino.cra...@gmx.de> wrote:
> >
> > > Hi,
> > >
> > > is there a racket function, which shuffles a list of items
> > > based on a seed value...that is: Same seed value results in
> > > same shuffle results?
> > >
> > > Cheers
> > > Meino
> > >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send
> an
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > For more options, visit https://groups.google.com/d/optout.
> > >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to racket-users+unsubscr...@googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
>
> HI Daniel,
>
> thanks a lot...exactly for what I have searched for!
>
> Cheers
> Meino
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to