Skip to content

Instantly share code, notes, and snippets.

@regularcoder
Created January 19, 2014 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regularcoder/8501660 to your computer and use it in GitHub Desktop.
Save regularcoder/8501660 to your computer and use it in GitHub Desktop.
Park-Miller Minimum Standard Random Number Generator in Common Lisp
(defun get-msrn-naive (x n)
(let ((a 16807) (m 2147483647))
(mod (*
a
;Multiply either by x or recursive call
(if (eq n 1)
x
(get-msrn-naive x (- n 1))))
m)))
(defun get-next-msrn (x)
(let (
(a 16807)
(m 2147483647)
(q 127773)
(r 2836)
)
(let
(
(result
(-
(* a (mod x q))
(* r (floor (/ x q)))
)
)
)
(if
(<= result 0)
(+ result m)
result
)
)
)
)
(defun get-msrn-schrage (x n)
(if (eq n 1)
(get-next-msrn x)
(get-msrn-schrage (get-next-msrn x) (- n 1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment