introductionToProgramming/week3/RollLoadedDie.java
Daniel Bulant 4bf15294e7
update
2025-09-23 12:00:00 +02:00

11 lines
493 B
Java

public class RollLoadedDie {
public static void main(String[] args) {
double rand8 = Math.random() * 8.;
// floor returns double. Round gives long for double input, so conversion needed
int random = (int)(Math.floor(rand8) + 1);
// 1 - 8 to 1 - 6, with 6 receiving the probabilities of 7 - 8
// 1 - 5 have their original probabilities, meaning each have 1/8 chance of being selected, while 6 is 3/8
random = Math.min(random, 6);
System.out.println(random);
}
}