Is it possible to generate random numbers of BigFloat
type uniformly distributed in the interval [0,1)?
I mean, since rand(BigFloat)
is not available it seems we have to use BigFloat(rand())
for that ending. However this is not satisfactory for me as we are generating random Float64
numbers that are converted to BigFloats
basically by "adding" a string of zeros, but in essence they are Float64
random numbers. Is this correct? If yes, is there any special library to generate random numbers with arbitrary precision?
To randomly permute an arbitrary vector, see shuffle or shuffle! . In Julia 1.1 randperm returns a vector v with eltype(v) == typeof(n) while in Julia 1.0 eltype(v) == Int . Construct in A a random permutation of length length(A) . The optional rng argument specifies a random number generator (see Random Numbers).
In Julia, you can set a seed to the random number generator using the srand() function. The code example below sets the seed to 1234. Generating a random variable with rand(1) after setting the seed to 1234 will always generate the same number, i.e. it will always return 0.5908446386657102.
For future readers (using Julia 0.7+) you can just do this with rand(BigFloat)
.
As of https://github.com/JuliaLang/julia/pull/22720
(You could certainly port that code to 0.6, and use it under the MIT license).
This is now working on 0.7-dev:
julia> rand(BigFloat)
5.381468355278042619008060591939155580805097923053455073547599255767645416051576e-01
julia> rand(BigFloat)
6.678413824545014328186230919629061895976571434256056298415613736582692882364622e-01
julia> rand(BigFloat)
1.388732949711447354224342960598222355426512649106497530016925083999303683268617e-01
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With