Output distribution of rand(Float32) and rand(Float64), thread 2

one takeaway I have from this thread is that basically each distribution needs to be implemented thoughtfully, and rand() should not be considered suitable to be naively used as a subroutine for randn, randexp, etc…

so with that being said, could be useful to add a method

julia> rand(Float64, 1.5:2.5)
ERROR: MethodError: no method matching rand(::Type{Float64}, ::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})

which will draw from uniform [a, b) with the same precision / approximation / uniformity properties as rand() has on [0, 1), given that the naive (rand() + a) / (b-a) may not be ideal

1 Like