[erlang-questions] On OTP rand module difference between OTP 19 and OTP 20
Richard A. O'Keefe
ok@REDACTED
Thu Aug 31 00:34:16 CEST 2017
On 30/08/17 6:42 PM, Raimo Niskanen wrote:
> On Wed, Aug 30, 2017 at 11:44:57AM +1200, Richard A. O'Keefe wrote:
>> There are applications of random numbers for which it is important
>> that 0 never be returned. Of course, nothing stops me writing
>
> What kind of applications? I would like to get a grip on how needed this
> function is?
I'll give you just one example. There are two ways I know to generate
normally distributed random numbers. One of them goes like this:
sqrt(-2 * ln(randnz()) * cos(pi * random())
where random() is in [0,1) but randnz() must be in (0,1).
OK, I'll give you another example. This is part of an algorithm for
generating gamma variates, one of the best known.
U <- random()
if U <= r then
z <- -ln(U/r)
else
z <- ln(random()/lambda)
end
You will notice that both of the calls to ln will go wrong if
random() can return 0.
These aren't the only examples, but I have an appointment.
More information about the erlang-questions
mailing list