If you are interested in previous discussions, you can have a look at random sampling from an (abstract)array is slow · Issue #20582 · JuliaLang/julia · GitHub and rand(1:10) vs Int(round(10*rand()) (and maybe RFC: implement a biased rand(a:b) (fix #20582) by rfourquet · Pull Request #28987 · JuliaLang/julia · GitHub which implements a biased rand(a:b)
).
Also, I don’t know which version of julia you are using, but on 1.3 and more, I will repeat myself by recommending to use an explicit RNG when you benchmark, if what you want to measure is the performance of the algorithm to sample from a range, i.e. @btime rand($rng, 1:3)
and not @btime rand(1:3)
where rng = MersenneTwister();
.