Error: You don't have JavaScript enabled. This tool uses JavaScript and much of it will not work correctly without it enabled. Please turn JavaScript back on and reload this page.

Please enter a title.

You can not post a blank message. Please type your message and try again.

So there should be an equal chance of xSpeed being
implemented as 10, -10 or 0 right? Instead I am finding that it is
always either 10 or -10.

If I change xRandom = random(3); to xRandom = random(4); then
each value has an equal chance of being implemented. But that
should be the case for random(3) surely!???

Also, if I change xRandom = random(3); to xRandom =
Math.random(3); then xSpeed always seems to end up as 10. What's
with that??? What difference does adding Math. make???

I must be missing something important about how random()
works because this isn't making any sense to me :(.

random(Number) picks a pseudorandom number from zero, to 1
minus the number you entered.
This makes it particularly useful with arrays, because they
are indexed starting with zero.

Try the following:

var numberArray = [10,-10,0];
xSpeed = numberArray[random(3)];