using rand MethodError: no method matching isless(::Array{Float64,1}, ::Float64)

Viewed 180

If I run the following code,

A = 0.2 
if rand(1)<0.85
   println(A)
end

the error is

MethodError: no method matching isless(::Array{Float64,1}, ::Float64)
Closest candidates are:

isless(!Matched::Missing, ::Any) at missing.jl:87

isless(!Matched::Float64, ::Float64) at float.jl:465

isless(!Matched::AbstractFloat, ::AbstractFloat) at operators.jl:165

I know that this is a simple code. But no idea why Julia is throwing this error. Please help.

1 Answers

You want if rand()<0.85. rand(1) generates a 1 element Vector of Float64. rand() generates a Float64.

Related