Shufflerator now shuffles like the NL one does!
[clnl] / src / main / random.lisp
index 44a1a2af0531f6d48e40109cbfa04f9283369bc1..6c9ecaa7c6fd42b6d4cba8653d665b74a42c29a2 100644 (file)
@@ -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
@@ -27,6 +30,6 @@
      'list
      (lambda (x) (if (logbitp (1- 32) x) (dpb x (byte 32 0) -1) x))
      (mt19937::random-state-state mt19937:*random-state*))))
-  (format nil "0 ~A ~A ~A 0.0 false ~{~A~^ ~}"
+  (format nil "0 ~A ~A ~A 0.0 false ~{~A~^ ~}"
    (first state) (second state) (third state)
-   (nthcdr 4 state))))
+   (nthcdr 3 state))))