1 (in-package #:cl-nl.random)
3 ; This is a wrapper around the very nice mersenne twister mt19937 to match
4 ; NetLogo's implementation that tries to match how java.util.Random works
7 (setf mt19937:*random-state* (mt19937::make-random-object :state (mt19937:init-random-state n))))
11 (= n (logand n (- n) ))
12 (ash (* n (ash (mt19937:random-chunk mt19937:*random-state*) -1) ) -31)
13 (rem (ash (mt19937:random-chunk mt19937:*random-state*) -1) n)))
15 (defun next-double (&optional (n 1d0))
17 ((y (mt19937:random-chunk mt19937:*random-state*))
18 (z (mt19937:random-chunk mt19937:*random-state*)))
21 (+ (ash (ash y -6) 27) (ash z -5))
22 (coerce (ash 1 53) 'double-float))
25 ; Oh, export world, you WILL be mine
31 (lambda (x) (if (logbitp (1- 32) x) (dpb x (byte 32 0) -1) x))
32 (mt19937::random-state-state mt19937:*random-state*))))
33 (format nil "0 ~A ~A ~A 0.0 false ~{~A~^ ~}"
34 (first state) (second state) (third state)