Rand not being random?

The trouble is that rand(S) returns a random element of the set S, and the set S you’re providing has only the element 0.0. For example, 0:0.3 is the set of Float64’s between 0.0 and 0.3 in default steps of 1.0. So 0:0.3 has only one element, 0.0.

Instead, use rnd = sum*rand(). The rand() will be a random Float64 between 0.0 and 1.0, which is then scaled to 0.0 to sum by the multiplication.

3 Likes