Loading

Paste #p7mvrq5jb

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