On 14.12.2008, at 18:40, Konrad Hinsen wrote: > (defn rng-uniform > "Return an infinite lazy sequence of random numbers" > [] > (drop 1 (iterate (fn [_] (rand)) nil))) > > (defn transform-to-gaussian > "Transform a sequence of uniform random number in the interval > [0, 1) > into a sequence of Gaussian random numbers." > [uniform-seq] > (let [[U1 U2 & uniform-rest] uniform-seq > V1 (- (* 2.0 U1) 1.0) > V2 (- (* 2.0 U2) 1.0) > S (+ (* V1 V1) (* V2 V2)) > LS (. Math sqrt (/ (* -2.0 (. Math log S)) S)) > X1 (* V1 LS) > X2 (* V2 LS)] > (if (or (>= S 1) (= S 0)) > (recur uniform-rest) > (lazy-cons X1 (lazy-cons X2 (transform-to-gaussian uniform- > rest))))))
I forgot to copy one part: (defn rng-gaussian [] (transform-to-gaussian (rng-uniform))) > ; Get 10 Gaussian random numbers > (take 10 (rng-gaussian)) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---