From 33383583acc82aa80516267d0ec7f9fa93d33bde Mon Sep 17 00:00:00 2001 From: Avril Date: Sun, 19 Apr 2020 21:46:50 +0100 Subject: [PATCH] shuffle --- cl-rng.lisp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cl-rng.lisp b/cl-rng.lisp index ab766e4..ca55ec7 100644 --- a/cl-rng.lisp +++ b/cl-rng.lisp @@ -26,3 +26,15 @@ (export 'weighted) +(defun shuffle! (sequence &key (provider *default-randomness-provider*)) + (if (listp sequence) + (loop for i from (1- (length sequence)) above 0 do + (rotatef (nth i sequence) + (nth (funcall provider :limit i :transform #'floor) sequence))) + (loop for i from (1- (length sequence)) above 0 do + (rotatef (aref sequence i) + (aref sequence (funcall provider :limit i :transform #'floor))))) + sequence) + +(export 'shuffle!) +