I’m making a game in Java where I need dices. There are 3 dices for the attacker and 2 dices for the defencer. This is my code that randomize the eyes on all dices:
if (attacker.getArmies() > 1)
aDices[0] = random.nextInt(6) + 1;
if (attacker.getArmies() > 2)
aDices[1] = random.nextInt(6) + 1;
if (attacker.getArmies() > 3)
aDices[2] = random.nextInt(6) + 1;
if (defencer.getArmies() > 0)
dDices[0] = random.nextInt(6) + 1;
if (defencer.getArmies() > 1)
dDices[1] = random.nextInt(6) + 1;
But why are the numbers of the ‘defence’ dices mostly higher then the ‘attack’ dices?
I’m using the Random class from java.util.Random
Seeing that you are using exactly the same function for attack and defense, it’s simply impossible that the outcome is structurally higher for attackers. What you could try to convince yourself is write a little function that rolls the dice a 100 times as attack and defense and calculate averages for that. And even then it is still possible that after a 100 times, attack wins a 100 times, unlikely, but possible. That’s the nature of randomness.
This is a nice short read on randomness for some background information:
http://engineering.mit.edu/live/news/1753-can-a-computer-generate-a-truly-random-number