18e71146fb25

Add `random-range-inclusive`
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 27 Dec 2016 00:07:07 -0500
parents 0f627d8ff8c3
children 7f37cc5260ec
branches/tags (none)
files DOCUMENTATION.markdown losh.lisp package.lisp

Changes

--- 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)
 
--- 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)
--- 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