Created
September 29, 2011 05:29
-
-
Save omasanori/1250044 to your computer and use it in GitHub Desktop.
A hobby implementation of linearcongruential generators.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn lcg | |
"Returns a lazy seq of random numbers using linear congruential | |
generators (LCGs)." | |
[seed a b m] | |
(map #(float (/ %)) | |
(drop 1 | |
(iterate (fn [x] (mod (+ (* a x) b) m)) | |
seed)))) | |
(defn lcg-average | |
"Returns average of x random numbers using LCGs with seed." | |
[x seed] | |
(let [ans (take x (lcg seed 997 1 65536))] | |
(/ (apply + ans) x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment