X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?p=clnl;a=blobdiff_plain;f=src%2Fmain%2Frandom.lisp;h=6c9ecaa7c6fd42b6d4cba8653d665b74a42c29a2;hp=508cb6b798681abaced12cfa0a3e2b813928c394;hb=d429346c4e41599eaae8de2f4baa9c1b8a81aea6;hpb=d4ab3334d216c9963f9459d9e8870c6abafce8f1 diff --git a/src/main/random.lisp b/src/main/random.lisp index 508cb6b..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