diff options
author | Thanos Apollo <[email protected]> | 2024-05-18 02:12:21 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-05-18 02:12:21 +0300 |
commit | dd4c8b60ce19e71ca68623c3e557e2d529f76b82 (patch) | |
tree | ae549692bbae8aeb8b280cb7676b08fb13a4139c /gnosis.el | |
parent | b9c6c04e33ad2f541ab116dda9e460f21034a8eb (diff) |
Add gnosis-shuffle
Diffstat (limited to 'gnosis.el')
-rw-r--r-- | gnosis.el | 8 |
1 files changed, 8 insertions, 0 deletions
@@ -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 |