# HG changeset patch # User Steve Losh # Date 1482815227 18000 # Node ID 18e71146fb25cde36e2fd967e6e31727baa30d60 # Parent 0f627d8ff8c3684ab5f3ac90df76de90a04c6059 Add `random-range-inclusive` diff -r 0f627d8ff8c3 -r 18e71146fb25 DOCUMENTATION.markdown --- a/DOCUMENTATION.markdown Mon Dec 26 15:25:35 2016 -0500 +++ b/DOCUMENTATION.markdown Tue Dec 27 00:07:07 2016 -0500 @@ -1273,13 +1273,19 @@ (RANDOM-RANGE MIN MAX) -Return a random number between [`min`, `max`). +Return a random number in [`min`, `max`). ### `RANDOM-RANGE-EXCLUSIVE` (function) (RANDOM-RANGE-EXCLUSIVE MIN MAX) -Return a random number between (`min`, `max`). +Return a random number in (`min`, `max`). + +### `RANDOM-RANGE-INCLUSIVE` (function) + + (RANDOM-RANGE-INCLUSIVE MIN MAX) + +Return a random number in [`min`, `max`]. ### `RANDOMP` (function) diff -r 0f627d8ff8c3 -r 18e71146fb25 losh.lisp --- a/losh.lisp Mon Dec 26 15:25:35 2016 -0500 +++ b/losh.lisp Tue Dec 27 00:07:07 2016 -0500 @@ -255,11 +255,15 @@ (values (elt seq (random length)) t)))) (defun-inlineable random-range (min max) - "Return a random number between [`min`, `max`)." + "Return a random number in [`min`, `max`)." (+ min (random (- max min)))) +(defun-inlineable random-range-inclusive (min max) + "Return a random number in [`min`, `max`]." + (+ min (random (1+ (- max min))))) + (defun-inlineable random-range-exclusive (min max) - "Return a random number between (`min`, `max`)." + "Return a random number in (`min`, `max`)." (+ 1 min (random (- max min 1)))) (defun random-around (value spread) diff -r 0f627d8ff8c3 -r 18e71146fb25 package.lisp --- a/package.lisp Mon Dec 26 15:25:35 2016 -0500 +++ b/package.lisp Tue Dec 27 00:07:07 2016 -0500 @@ -227,6 +227,7 @@ :random-elt :random-range :random-range-exclusive + :random-range-inclusive :random-around :random-gaussian :random-gaussian-integer