Rename to clnl, add documentation
[clnl] / src / main / random.lisp
index 508cb6b798681abaced12cfa0a3e2b813928c394..6f500a979558a57fdd519d4323878ab43a5e8052 100644 (file)
@@ -1,4 +1,4 @@
-(in-package #:cl-nl.random)
+(in-package #:clnl-random)
 
 ; This is a wrapper around the very nice mersenne twister mt19937 to match
 ; NetLogo's implementation that tries to match how java.util.Random works
@@ -7,7 +7,10 @@
  (setf mt19937:*random-state* (mt19937::make-random-object :state (mt19937:init-random-state n))))
 
 (defun next-int (n)
- (rem (ash (mt19937:random-chunk mt19937:*random-state*) -1) n))
+ (if
+  (= n (logand n (- n) ))
+  (ash (* n (ash (mt19937:random-chunk mt19937:*random-state*) -1) ) -31)
+  (rem (ash (mt19937:random-chunk mt19937:*random-state*) -1) n)))
 
 (defun next-double (&optional (n 1d0))
  (let