user5045
user5045

Reputation: 241

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

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.

Upvotes: 1

Views: 249

Answers (1)

Oscar Smith
Oscar Smith

Reputation: 6398

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

Upvotes: 3

Related Questions