[erlang-questions] On OTP rand module difference between OTP 19 and OTP 20
Michael Truog
<>
Fri Sep 1 13:00:59 CEST 2017
On 09/01/2017 01:54 AM, Raimo Niskanen wrote:
> On Thu, Aug 31, 2017 at 10:29:34PM -0700, Michael Truog wrote:
> :
>> I have some examples that can make this desire a bit clearer:
>>
>> https://github.com/CloudI/cloudi_core/blob/a1c10a02245f0f4284d701a2ee5f07aad17f6e51/src/cloudi_core_i_runtime_testing.erl#L139-L149
>>
>> % use Box-Muller transformation to generate Gaussian noise
>> % (G. E. P. Box and Mervin E. Muller,
>> % A Note on the Generation of Random Normal Deviates,
>> % The Annals of Mathematical Statistics (1958),
>> % Vol. 29, No. 2 pp. 610–611)
>> X1 = random(),
>> X2 = PI2 * random(),
>> K = StdDev * math:sqrt(-2.0 * math:log(X1)),
>> Result1 = erlang:max(erlang:round(Mean + K * math:cos(X2)), 1),
>> Result2 = erlang:max(erlang:round(Mean + K * math:sin(X2)), 1),
>> sleep(Result2),
> Why not use rand:normal/3?
>
> It uses the Ziggurat Method and is supposed to be much faster and
> numerically more stable than the basic Box-Muller method.
>
The Box-Muller is simpler and producing 2 results instead of 1 . I believe I looked at the source code for rand:normal/3 and expected the Box-Muller to be faster only because it creates 2 results, though I should check that. I will have to investigate it more.
More information about the erlang-questions
mailing list