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

Richard A. O'Keefe <>
Wed Aug 30 01:44:57 CEST 2017



On 29/08/17 8:35 PM, Raimo Niskanen wrote:
>
> Regarding the changed uniform float behaviour: it is the functions
> rand:uniform/0 and rand:uniform_s/1 this concerns.  They were previously
> (OTP-19.3) documented to output a value 0.0 < X < 1.0 and are now
> (OTP-20.0) documented to return 0.0 =< X < 1.0.

There are applications of random numbers for which it is important
that 0 never be returned.  Of course, nothing stops me writing

uniform_nonzero() ->
     X = rand:uniform(),
     if X >  0.0 -> X
      ; X =< 0.0 -> uniform_nonzero()
     end.

but it would be nice to have this already in the library.

(I know the old library had the same gap.  But with such a major
reworking of random number generation, it's time to close it.)



More information about the erlang-questions mailing list