That is correct. If Julia can conclude it does not need to compute, it will not.
julia> f(n) = n + 3
f (generic function with 1 method)
julia> g(n) = (n + 3; nothing)
g (generic function with 1 method)
julia> @code_llvm f(5)
; @ REPL[1]:1 within `f`
define i64 @julia_f_136(i64 signext %0) #0 {
top:
; ┌ @ int.jl:87 within `+`
%1 = add i64 %0, 3
; └
ret i64 %1
}
julia> @code_llvm g(5)
; @ REPL[2]:1 within `g`
define void @julia_g_147(i64 signext %0) #0 {
top:
ret void
}
rand is a bad example though. rand does have an effect. It will change the next call to rand.