Loading

Paste #p2kkjc9y8

  1. (defmacro do-with-%-chance-of (percent &body body)
  2.   (cond ((>= 0 percent) nil)
  3.         ((<= 100 percent) `(progn ,@body))
  4.         (t (let ((calculation (cond ((>= percent 100) 100)
  5.                                     ((zerop percent)  0)
  6.                                     (t '(1+ (random 100))))))
  7.              `(when (<= ,calculation ,percent)
  8.                 ,@body)))))