Generating random integer in range in julia -
i migrating matlab julia , trying generate random integer in range 1:n
for n < 21,
rand(r[1:n]) works.
however n > 20, e.g rand(r[1:21])
i message.
error: boundserror() in getindex @ range.jl:121
you can give range first argument rand, in rand(1:n):
julia> rand(1:10) 7 julia> rand(1:10,10,10) 10x10 array{int64,2}: 10 2 5 8 5 5 3 7 1 3 5 1 4 2 4 4 1 6 6 9 8 1 3 9 4 8 7 8 7 10 3 8 1 5 7 9 7 8 10 7 5 8 5 6 6 2 2 7 4 3 10 4 8 8 10 5 1 10 5 1 6 1 8 1 6 5 7 10 6 10 5 10 2 5 4 5 4 1 3 9 5 4 6 4 4 1 7 8 1 5 10 2 6 4 3 10 7 3 8 7 the first argument general rand function gives "thing sample from", range of values or distribution object defined in distributions.jl.
julia-lang
No comments:
Post a Comment