Roll cube with 50% chance of rolling 6
So I did this way of rolling the dice 100 times with a 50% chance of rolling 6. The basic idea is that there are 50% odd numbers and 50% even numbers between 1 and 6, so if an even number is collapsed, the system prints 6. otherwise it prints a random number from 1 to 5. Do you think this is correct?
public static void printDiceRolls(Random randGenerator) {
for (int i=0; i < 30; i++) {
int temp;
temp = randGenerator.nextInt(6) + 1;
if (temp%2 == 0) {
temp = 6;
}
else
temp = randGenerator.nextInt(5) + 1;
System.out.print(" " + temp + " ");
}
}
source to share
Create a random number between 1 and 10, inclusive at both ends. If the number should be between 1 and 5, you produced that number, otherwise you rolled 6. Note that in this scheme there are 5 chances of rolling 6 (i.e. 50%) and 5 overall chances of rolling 1-5 (i.e. i.e. the other 50%).
Random random = new Random();
int roll = random.nextInt(10) + 1;
if (roll > 5) {
System.out.println("You rolled a 6");
}
else {
System.out.println("You rolled a " + roll);
}
source to share
Die with a 50% chance of rolling 6
The following method guarantees that 50% of the bones are 6, but they will not come alternatively ... I think this is the best way to ensure that 6 is sliced exactly 50% of the times, but not in an alternating sequence, which makes the result more believable in my opinion ...
In my opinion you only need to do this:
public static void naturalDicingWithVariablePercentageOfSix(int totalDice,int probability)
{
Random rand=new Random();
List<Integer> diceList=new ArrayList<Integer>();
System.out.println(""+( (int)(100/probability))+"% times that six being diced \n\n");
for(int i=0;i<totalDice;i++)
{
if(i%probability==0)
diceList.add(6);
else
diceList.add(rand.nextInt(5)+1);
}
Collections.shuffle(diceList);
int notSixCount=0;
int sixCount=0;
for(Integer diceVal:diceList)
{
if(diceVal!=6)
notSixCount++;
else
sixCount++;
System.out.print(diceVal+" ");
}
System.out.println("\n\n Not 6 being diced : "+notSixCount+" times "+" and Six being diced :"+sixCount+"\n\n");
}
Input:
naturalDicingWithVariablePercent6(100,2); // 50% times 6
naturalDicingWithVariablePercent6(100,3); // 33% times 6
naturalDicingWithVariablePercent6(100,4); // 25% times 6
naturalDicingWithVariablePercent6(100,5); // 20% times 6
naturalDicingWithVariablePercent6(100,6); // 16.67% times 6
Output:
50% of the time when six dice
4 3 6 6 3 5 4 6 2 1 6 6 6 6 1 6 6 4 3 5 6 6 5 4 2 5 6 2 1 6 5 5 1 6 6 6 2 6 4 6 6 4 6 6 6 6 2 1 6 3 6 4 3 5 6 6 5 6 6 6 6 6 4 2 6 3 3 6 3 6 6 6 3 5 2 5 6 6 3 2 6 6 6 5 4 6 4 4 3 6 5 4 6 1 6 6 6 6 5 6
Not 6 diced: 50 times, but six - diced: 50
33% times six dice
2 6 1 6 5 2 1 5 6 5 6 3 3 2 1 3 5 3 6 6 4 4 2 6 6 1 1 4 2 6 6 3 6 2 6 5 6 4 1 3 6 4 1 1 2 6 5 6 6 6 2 4 2 2 3 6 4 3 4 1 6 4 4 2 4 6 6 4 5 4 6 6 2 4 4 5 3 6 6 6 3 6 6 1 2 4 1 4 6 6 6 5 4 4 5 5 6 2 3 6
Not 6 diced: 66 times and six diced: 34
25% times when six dice
6 1 3 4 6 4 4 2 4 1 6 3 6 1 1 3 3 5 3 4 1 2 3 3 6 3 3 4 5 5 2 6 5 2 3 1 1 4 4 6 5 4 2 3 5 6 3 4 6 4 6 6 5 6 6 5 1 6 6 6 2 3 6 3 6 4 6 5 3 4 5 2 4 2 1 6 3 5 6 3 2 1 4 1 3 6 4 6 6 5 5 5 5 4 2 1 2 3 3 6
Not 6 diced: 75 times and six diced: 25
20% of the times six were diced
6 4 6 1 3 5 4 4 1 4 4 1 4 5 6 3 4 3 2 3 3 5 2 1 3 3 2 6 1 3 5 6 5 2 2 6 3 1 2 2 1 6 2 1 3 1 1 1 1 1 5 4 4 6 2 2 2 2 1 6 3 5 6 5 3 6 6 5 2 4 3 2 6 4 6 6 6 6 3 5 2 3 2 4 4 5 4 2 1 6 1 6 6 3 3 5 2 5 2 5
Not 6 diced: 80 times and six diced: 20
16% times when six dice
5 4 2 2 4 4 6 2 2 1 3 5 4 2 5 5 6 5 3 3 4 3 3 5 3 1 6 5 3 6 2 4 6 6 5 4 4 6 6 5 6 5 1 3 4 3 2 1 1 6 1 1 4 4 3 3 1 3 5 3 2 6 5 4 4 2 6 4 6 3 1 4 2 3 1 1 1 1 3 3 5 2 3 3 6 6 2 3 3 5 5 1 1 6 4 6 3 2 2
Not 6 diced: 83 times, but 6 diced: 17
source to share