@. rand(n) > 0.5 is equivalent to rand.(2) .> 0.5 and not rand(2) .> 0.5. The former is equivalent to
julia> for i in 2
rand(i) > 0.5
end
Perhaps you want something like
julia> @. (i -> 2 * (rand() > 0.50) - 1)(1:4)
4-element Vector{Int64}:
-1
-1
-1
-1
or, more clearly,
julia> [2 * (rand() > 0.50) - 1 for i in 1:4]
4-element Vector{Int64}:
1
-1
1
1