summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-05-18 02:12:21 +0300
committerThanos Apollo <[email protected]>2024-05-18 02:12:21 +0300
commitdd4c8b60ce19e71ca68623c3e557e2d529f76b82 (patch)
treeae549692bbae8aeb8b280cb7676b08fb13a4139c /gnosis.el
parentb9c6c04e33ad2f541ab116dda9e460f21034a8eb (diff)
Add gnosis-shuffle
Diffstat (limited to 'gnosis.el')
-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