[erlang-questions] On OTP rand module difference between OTP 19 and OTP 20

Raimo Niskanen raimo+erlang-questions@REDACTED
Mon Sep 25 11:07:09 CEST 2017


On Fri, Sep 08, 2017 at 02:26:28PM +0200, Raimo Niskanen wrote:
> To conclude
> ===========
> 
> It would be convenient to have functions in the rand module that
> generates on the interval (0.0, 1.0] e.g rand:uniform_nonzero/0
> and rand:uniform_nonzero_s/1 or maybe rand:uniform_nz/0
> and rand:uniform_nz_s/1.
> 
> But since it is very easy to use e.g (1.0 - rand:uniform()) I see
> little value in adding them.  Adding hints in the documentation could
> suffice.
> 
> However, I think we could add functions with the same names and
> interval that also has got a different uniformity i.e still uniform,
> but not equidistant, instead increasing precison towards 0.  This would
> have a greater value.  Such a uniformity would work better for some
> suggested algorithms such as Box-Muller.
> 
> Ironically, the implementation by Kenji that I changed was a few bits in
> that direction i.e used the generators' extra bits over 53 (5 or 11)
> for increased precision, but I want to have at least 53 extra bits which I
> hope is close enough to infinity.
> 
> I have implemented such functions in my own GitHub repo, but ran into
> problems with the number distribution that I suspect is caused by
> rounding errors in the current implementation of erlang:float/1.
> 
> So I will try to find the time to investigate that further...

I have created a pull request with such an extension to the rand module:
    https://github.com/erlang/otp/pull/1574

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list