+ 1
Java- dice rolling program
The goal is to create a program that beat simulated the value produced as a result of rolling 2 number cubes (their sum, 1-6 inclusive, equal probability that it is any of the numbers). Which method below is the best and why? (int) (Math.random() * 13); Or 2+ (int) (Math.random()*6) + (int)(Math.random() * 6) Thanks!
1 Resposta
+ 5
Hello
I would use Random rnd = new Random();
rnd.nextInt(6) + rnd.nextInt(6) + 2;
In your case the second option looks more efficient than the 1st one.