You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(defunkey-quiz--shuffle-list (list)
"Shuffles LIST randomly, modying it in-place."
(dolist (i (reverse (number-sequence1 (1- (lengthlist)))))
(let ((j (random (1+ i)))
(tmp (eltlist i)))
(setf (eltlist i) (eltlist j))
(setf (eltlist j) tmp)))
list)
(defunkey-quiz--shuffle-list-nreverse (list)
"Shuffles LIST randomly, modying it in-place."
(dolist (i (nreverse (number-sequence1 (1- (lengthlist)))))
(let ((j (random (1+ i)))
(tmp (eltlist i)))
(setf (eltlist i) (eltlist j))
(setf (eltlist j) tmp)))
list)
(defunelfeed--shuffle (seq)
"Destructively shuffle SEQ."
(let ((n (length seq)))
(prog1 seq ; don't use dotimes result (bug#16206)
(dotimes (i n)
(cl-rotatef (elt seq i) (elt seq (+ i (random (- n i)))))))))
(defunfaster-seq-sort-by (functionpredsequence)
"Sort SEQUENCE using PRED as a comparison function.Elements of SEQUENCE are transformed by FUNCTION before beingsorted. FUNCTION must be a function of one argument.";; This version is modified to avoid calling "random" twice every time the predicate is called.
(seq-map'cdr
(sort (seq-map (lambda (x) (cons (funcall function x) x)) sequence)
(lambda (ab)
(funcall pred (car a) (car b))))))
(defunseq-sort-by--shuffle (seq)
(seq-sort-by (lambda (_) (random)) #'<= seq))
(defunfaster-seq-sort-by--shuffle (seq)
(faster-seq-sort-by (lambda (_) (random)) #'<= seq))