X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=clnl;a=blobdiff_plain;f=src%2Fmain%2Frandom.lisp;h=6c9ecaa7c6fd42b6d4cba8653d665b74a42c29a2;hp=44a1a2af0531f6d48e40109cbfa04f9283369bc1;hb=d429346c4e41599eaae8de2f4baa9c1b8a81aea6;hpb=1ae8c7a0199a4955708c7f5d7a286a12782b5fd2 diff --git a/src/main/random.lisp b/src/main/random.lisp index 44a1a2a..6c9ecaa 100644 --- a/src/main/random.lisp +++ b/src/main/random.lisp @@ -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 1 ~{~A~^ ~}" + (format nil "0 ~A ~A ~A 0.0 false ~{~A~^ ~}" (first state) (second state) (third state) - (nthcdr 4 state)))) + (nthcdr 3 state))))