How can I get the Math.random() call to have absolute equal probability for 4 cases? (ie 0.25 for case 1, 0.25 for case 2, 0.25 for case 3, 0.25 for case 4)?
I currently get 0.05 for Case 1, 0.075 for Case 2, 0.45 for Case 3 and 0.425 for Case 4.
Been trying to work out why it does this for hours with not much success.
int direction = 0;
// Select a random number
randno = (int) Math.round(Math.random() * 3);
// Convert this to a direction
while (direction == 0) {
if (randno == 0 && !isWall(robot, Robot.LEFT)) direction = Robot.LEFT;
else if (randno == 1 && !isWall(robot, Robot.RIGHT)) direction = Robot.RIGHT;
else if (randno == 2 && !isWall(robot, Robot.BEHIND)) direction = Robot.BEHIND;
else if (!isWall(robot, Robot.AHEAD)) direction = Robot.AHEAD;
else randno = (int) Math.round(Math.random() * 3);
}