insectoid @ Tue Nov 25, 2008 4:09 pm wrote:
use Math.random (). This returns a random decimal between 0 and 1. So (int) (Math.random ()*4) will give a random number between 1 and 4 (I think...Haven't used it in a while). (int) will convert the random number to an integer. I don't think it rounds, I think it just cuts off the decimal..Though I may be wrong...
The range is [0, 1). So if you have choices in range [1, 4], you need to multiply by 4 to get range [0, 4). Cast to int to get [0, 3] and add one to get [1, 4].