我在Clojure中总结了一长串比率,例如:
(defn sum-ratios
[n]
(reduce
(fn [total ind]
(+
total
(/
(inc (rand-int 100))
(inc (rand-int 100)))))
(range 0 n)))
Run Code Online (Sandbox Code Playgroud)
各种n的运行时间是:
(不太精确)替代方案是将这些值加总为双精度:
(defn sum-doubles
[n]
(reduce
(fn [total ind]
(+
total
(double
(/
(inc (rand-int 100))
(inc (rand-int 100))))))
(range 0 n)))
Run Code Online (Sandbox Code Playgroud)
此版本的运行时为: