Function: cookie-shuffle-vector

cookie-shuffle-vector is a byte-compiled function defined in cookie1.el.gz.

Signature

(cookie-shuffle-vector VECTOR)

Documentation

Randomly permute the elements of VECTOR (all permutations equally likely).

Aliases

shuffle-vector (obsolete since 24.4)

Source Code

;; Defined in /usr/src/emacs/lisp/play/cookie1.el.gz
;; Thanks to Ian G Batten <BattenIG@CS.BHAM.AC.UK>
;; [of the University of Birmingham Computer Science Department]
;; for the iterative version of this shuffle.
(defun cookie-shuffle-vector (vector)
  "Randomly permute the elements of VECTOR (all permutations equally likely)."
  (let ((len (length vector))
	j temp)
    (dotimes (i len)
      (setq j (+ i (random (- len i)))
	    temp (aref vector i))
      (aset vector i (aref vector j))
      (aset vector j temp))
    vector))