Math.random() returns a number in the interval [0, 1), right?
So, if I need to change the interval to (-1, 1), would I use do this...
xCoord = Math.random() * 2 - 1;
to change the range to be 2 (so it'd be [0, 2) then subtract one to shift it to (-1, 1)?
A small nitpick: if you multiply the range [0,1) by two you get the range [0,2);
after subtracting one you get the range [-1,1). Note the inclusion on the left
side and exclusion on the right side.
The solution is simple: while the original random value happens to be zero,
generate another random number.
kind regards,
Jos