This answer is similar to @Dan Getz's but I more trust that it is uniform (to be honest, I did not do the chi ^ 2 test to check, or graphics, or anything else). @ Maybe I'm just not sure. This answer also takes into account the accuracy level of BigFloat that you can customize. (It is counter-intuitively possible that some BigFloatmay have less accuracy than usual Float64, etc.)
Base.rand(::Type{BigFloat}) = get(tryparse(BigFloat, "0." .* join(rand(['0','1'], precision(BigFloat))), 2))
Example:
julia> rand(BigFloat)
5.775971375531676786209502831045802088939348666270278366043732289527176430673822e-02
julia> rand(BigFloat)
3.061194516436133765062723761241255852372302334681778915000436918803432772307184e-01
julia> rand(BigFloat)
1.39772524343615633719535808470123032232713877796596771875414945796651457395665e-01
It is assumed that BigFloat has a known accuracy, so we must generate many random bits. Since we generate between [0,1), we know that the base-2 representation is 0.something. So, we generate the string in base-2 and analyze it in base 2.
source
share