I'm currently working on a small game that needs to return either 1,2 or 3.
The idea is that I then compare two numbers and the greater wins.
The code i'm using is this:
var isMultipleOf, number1, number2, random;
random = function(number) {
return isMultipleOf(Math.floor((Math.random() * number) + 1));
};
isMultipleOf = function(number) {
if (number % 2 === 0) {
return 1;
}
if (number % 3 === 0) {
return 2;
} else {
return 3;
}
};
number1 = random((Math.random() * 100) + 1);
number2 = random((Math.random() * 100) + 1);
console.log("number 1 is " + number1 + " and number2 is " + number2);
This code works, but i'd like to improve it a bit if possible.
With my game, a draw is possible, but with my current logic it happens quite often and I don't like it. Can you suggest a better way to improve this making it less possible to get a draw (same numbers)?
thanks