1 ; Copyright 2022 Frank Duncan (frank@consxy.com) under AGPL3. See distributed LICENSE.txt.
2 (in-package #:clnl-nvm)
4 (defun random-float (n)
5 "RANDOM-FLOAT N => RANDOM-NUMBER
9 N: a double, the upper bound of the random float
10 RANDOM-NUMBER: a double, the random result
14 Returns a random number strictly closer to zero than N.
16 If number is positive, returns a random floating point number greater than
17 or equal to 0 but strictly less than number.
19 If number is negative, returns a random floating point number less than or equal
20 to 0, but strictly greater than number.
22 If number is zero, the result is always 0.
24 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-float"
25 (clnl-random:next-double n))
28 "RANDOM N => RANDOM-NUMBER
32 N: an integer, the upper bound of the random
33 RANDOM-NUMBER: an integer, the random result
37 Returns a random number strictly closer to zero than N.
39 If number is positive, returns a random integer greater than or equal to 0,
40 but strictly less than number.
42 If number is negative, returns a random integer less than or equal to 0,
43 but strictly greater than number.
45 If number is zero, the result is always 0.
47 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random"
48 (coerce (clnl-random:next-long (truncate n)) 'double-float))