Loading

Paste #psscu3tcv

  1. ;; From this:
  2. (defmacro with-percent-chance (percent &body body)
  3.   (alexandria:with-gensyms (num calculation)
  4.     (setf calculation (cond ((>= percent 100) 100)
  5.                             ((zerop percent)  0)
  6.                             (t '(1+ (random 100)))))
  7.     `(let ((,num ,calculation))
  8.        (cond ((zerop ,num) 0)
  9.              ((<= ,num ,percent) ,@body)
  10.              (t nil)))))
  11.  
  12.  
  13. ;; To this:
  14. (defmacro do-with-%-chance-of (percent &body body)
  15.   (cond ((>= 0 percent) nil)
  16.         ((<= 100 percent) `(progn ,@body))
  17.         (t `(when (<= (1+ (random 100)) ,percent)
  18.               ,@body))))