Skip to content

Instantly share code, notes, and snippets.

@collinalexbell
Created August 2, 2017 07:43
Show Gist options
  • Save collinalexbell/c81e77c99463bb4b774c8218ef88e584 to your computer and use it in GitHub Desktop.
Save collinalexbell/c81e77c99463bb4b774c8218ef88e584 to your computer and use it in GitHub Desktop.
(defun box-muler-sample ()
(* (sqrt (* -2 (log (random 1.0)))) (cos (* 2 pi (random 1.0)))))
(defun simulate-height-expiriement ()
(let ((count 0)
(max -9999))
(dotimes (i 1000)
(let ((new-sample (box-muler-sample)))
(if (> new-sample max)
(progn
(incf count)
(setf max new-sample)))))
count))
(defun run-x-expiriments (x)
(loop for i from 1 to x
collect (simulate-height-expiriement)))
(defun avg (x)
(float (/ (reduce #'+ x) (length x))))
;;(avg (RUN-X-EXPIRIMENTS 4000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment