- [Function]
(
shuffle
list {keyword value}*)
Returns a random ordering of list according to the keyword arguments specified to the function.
shuffle
supports the following keyword arguments:
:copy
boolean- If true then list is copied before it is shuffled otherwise list is destructively modified. The default value is true.
:start
integer- An optional lower bound on element reordering.
:end
integer- An optional exclusive upper bound on element reordering.
:state
random-state- The random state to use. The default value is
*random-state*
.
Examples:
Example 1. The shuffle
function.
(shuffle '(a b c d e)) ⇒ (b a e d c) (shuffle '(a b c d e)) ⇒ (c e b a d) (shuffle '(a b c d e) :start 2) ⇒ (a b e d c) (shuffle '(a b c d e) :start 2) ⇒ (a b d e c)
Example 2. Shuffling notes.
(define (play-shuffle reps notes rate ) (let ((len (length notes))) (process for i below reps for j = (mod i len) when (= j 0) ; need to reshuffle? do (shuffle notes :copy #f) output (new midi :time (now) :keynum (list-ref notes j) :duration (* rate 1.5) :amplitude (interp j 0 .4 (- len 1) .8)) wait rate))) (events (play-shuffle 60 (note '(c d ef f g a bf c5)) .1) "test.mid") ⇒ "test.mid"