summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnosis.el8
1 files changed, 8 insertions, 0 deletions
diff --git a/gnosis.el b/gnosis.el
index 27c57e8..d633e06 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -274,6 +274,14 @@ Example:
(emacsql-with-transaction gnosis-db (gnosis--delete 'decks `(= id ,id)))
(message "Deleted deck `%s'" deck-name))))
+(defun gnosis-shuffle (seq)
+ "Shuffle SEQ."
+ (cl-loop with len = (length seq)
+ for i from len downto 2
+ do (let ((j (random i))) ; Get random index < i.
+ (cl-rotatef (nth (1- i) seq) (nth j seq))) ; Swap elements.
+ finally return seq))
+
(defun gnosis-replace-item-at-index (index new-item list)
"Replace item at INDEX in LIST with NEW-ITEM."
(cl-loop for i from 0 for item in list