【发布时间】:2012-07-01 20:11:03
【问题描述】:
第一种方法没问题。 第二个不断重复同一对数字。
这对我来说很模糊,为什么...你能指出好的方向吗?
module Normal =
let rnd = new MersenneTwister()
let sampleNormal =
fun () -> let rec randomNormal() = let u1, u2 = rnd.NextDouble(),rnd.NextDouble()
let r, theta= sqrt (-2. * (log u1)), 2. * System.Math.PI * u2
seq { yield r * sin theta; yield r * cos theta ; printfn "next";yield! randomNormal() }
randomNormal()
let sampleNormalBAD =
fun () -> let rec randomNormal = let u1, u2 = rnd.NextDouble(),rnd.NextDouble()
let r, theta= sqrt (-2. * (log u1)), 2. * System.Math.PI * u2
seq { yield r * sin theta; yield r * cos theta ; printfn "next";yield! randomNormal }
randomNormal
Normal.sampleNormal() |> Seq.take(10) |>Seq.toArray
Normal.sampleNormalBAD() |> Seq.take(10) |>Seq.toArray
【问题讨论】:
-
我猜它与不变性有关。