Reworked two pseudorandom number generating statements to avoid a bug in which the Math.random() result 0 would cause invalid numbers