[erlang-questions] On OTP rand module difference between OTP 19 and OTP 20
Raimo Niskanen
raimo+erlang-questions@REDACTED
Fri Sep 1 10:54:39 CEST 2017
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.
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list