JuliaRandom / RandomNumbers.jl

Random Number Generators for the Julia Language.
https://juliarandom.github.io/RandomNumbers.jl/stable
Other
97 stars 23 forks source link

randfloat(Float16) #75

Closed milankl closed 3 years ago

milankl commented 3 years ago

That's the Float16-version of randfloat. As there's only 15360 float16s to sample from in [0,1), randfloat can also produce zero(Float16) and subnormals are as likely as [floatmin,2floatmin), which is as it should be!

milankl commented 3 years ago

For N = 100_000_000


julia> H/N
15-element Array{Float64,1}:
 0.50000303    # chance of getting [1/2,1)
 0.25001156    # chance of getting [1/4,1/2)
 0.12499344    # etc.
 0.06245242
 0.03128043
 0.01562954
 0.00781335
 0.003909
 0.00195287
 0.00097575
 0.00049205
 0.00024423
 0.00012155
 6.068e-5       # chance of getting [floatmin,2floatmin)
 6.01e-5        # chance of getting a subnormal (0 included)
milankl commented 3 years ago

Hmm, randfloat() segfaults when called with an unsupported format

julia> using RandomNumbers, Float8s
julia> randfloat(Float8,100)
zsh: segmentation fault  julia