You can use Distributions and the rand
function for this. Any distribution can be passed to rand
. To replicate what you want:
julia> using Distributions
julia> p = Binomial(1, 0.3) # first arg is number of trials, second is probability of success
Binomial{Float64}(n=1, p=0.3)
julia> rand(p, 20)
20-element Array{Int64,1}:
0
1
1
0
1
0
0
1
0
1
1
1
0
0
1
0
1
0
0
1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…