# HG changeset patch # User Steve Losh # Date 1482815755 18000 # Node ID 7f37cc5260ec9a9478c8652efbb4dc7406def340 # Parent 18e71146fb25cde36e2fd967e6e31727baa30d60 Try to unfuck the random-range stuff for floats diff -r 18e71146fb25 -r 7f37cc5260ec losh.lisp --- a/losh.lisp Tue Dec 27 00:07:07 2016 -0500 +++ b/losh.lisp Tue Dec 27 00:15:55 2016 -0500 @@ -229,6 +229,14 @@ ;;;; Random ------------------------------------------------------------------- +(defun-inline epsilon (val) + (etypecase val + (integer 1) + (short-float short-float-epsilon) + (long-float long-float-epsilon) + (single-float single-float-epsilon) + (double-float double-float-epsilon))) + (defun-inlineable randomp (&optional (chance 0.5)) "Return a random boolean with `chance` probability of `t`." (< (random 1.0) chance)) @@ -260,11 +268,11 @@ (defun-inlineable random-range-inclusive (min max) "Return a random number in [`min`, `max`]." - (+ min (random (1+ (- max min))))) + (+ min (random (+ (- max min) (epsilon min))))) (defun-inlineable random-range-exclusive (min max) "Return a random number in (`min`, `max`)." - (+ 1 min (random (- max min 1)))) + (+ (epsilon min) min (random (- max min (epsilon min))))) (defun random-around (value spread) "Return a random number within `spread` of `value`."