Implementing Box-Mueller random number generator in C#

前端 未结 5 542
谎友^
谎友^ 2020-12-14 23:15

From this question: Random number generator which gravitates numbers to any given number in range? I did some research since I\'ve come across such a random number generator

5条回答
  •  青春惊慌失措
    2020-12-14 23:53

    Your code is fine. Your mistake is thinking that it should return values exclusively within [0, 1]. The (standard) normal distribution is a distribution with nonzero weight on the entire real line. That is, values outside of [0, 1] are possible. In fact, values within [-1, 0] are just as likely as values within [0, 1], and moreover, the complement of [0, 1] has about 66% of the weight of the normal distribution. Therefore, 66% of the time we expect a value outside of [0, 1].

    Also, I think this is not the Box-Mueller transform, but is actually the Marsaglia polar method.

提交回复
热议问题