405 |
(defun symbol< (x &rest args) |
(defun symbol< (x &rest args) |
406 |
(apply #'string< (symbol-name x) (mapcar #'symbol-name args))) |
(apply #'string< (symbol-name x) (mapcar #'symbol-name args))) |
407 |
|
|
|
(defun random-from-seq (seq) |
|
|
"Generate a random member of a sequence." |
|
|
(let ((len (length seq))) |
|
|
(assert (> len 0)) |
|
|
(elt seq (random len)))) |
|
|
|
|
|
(defmacro random-case (&body cases) |
|
|
(let ((len (length cases))) |
|
|
(assert (> len 0)) |
|
|
`(case (random ,len) |
|
|
,@(loop for i from 0 for e in cases collect `(,i ,e)) |
|
|
(t (error "Can't happen?! (in random-case~%"))))) |
|
|
|
|
|
(defun coin (&optional (n 2)) |
|
|
"Flip an n-sided coin." |
|
|
(eql (random n) 0)) |
|
|
|
|
|
;;; Randomly permute a sequence |
|
|
(defun random-permute (seq) |
|
|
(setq seq (copy-seq seq)) |
|
|
(let ((len (length seq))) |
|
|
(loop for i from len downto 2 |
|
|
do (let ((r (random i))) |
|
|
(rotatef (elt seq r) (elt seq (1- i)))))) |
|
|
seq) |
|
408 |
|
|
409 |
(defun make-list-expr (args) |
(defun make-list-expr (args) |
410 |
"Build an expression for computing (LIST . args), but that evades |
"Build an expression for computing (LIST . args), but that evades |