Skip to content

Commit

Permalink
Merge pull request #685 from vyzo/feat/shuffle-rng
Browse files Browse the repository at this point in the history
allow using a custom rng in shuffle
  • Loading branch information
vyzo authored Aug 1, 2022
2 parents 1eb0573 + b50187f commit 8e114a3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/std/misc/shuffle.ss
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
;;; shuffling

(export shuffle vector-shuffle vector-shuffle!)
(import (only-in :gerbil/gambit/random random-integer))
(import :gerbil/gambit/random)

(def (shuffle lst)
(def (shuffle lst (rng default-random-source))
(vector->list
(vector-shuffle!
(list->vector lst))))
(list->vector lst)
rng)))

(def (vector-shuffle vec)
(vector-shuffle! (vector-copy vec)))
(def (vector-shuffle vec (rng default-random-source))
(vector-shuffle! (vector-copy vec) rng))

(def (vector-shuffle! vec)
(def (vector-shuffle! vec (rng default-random-source))
(def random-integer
(random-source-make-integers rng))
(let (len (vector-length vec))
(do ((i 0 (##fx+ i 1)))
((##fx= i len) vec)
Expand Down

0 comments on commit 8e114a3

Please sign in to comment.