22 lines
767 B
Java
22 lines
767 B
Java
|
import java.util.concurrent.ThreadLocalRandom;
|
||
|
|
||
|
public class code_unoptimised {
|
||
|
public static void main(String[] args) {
|
||
|
int total_attempts = 15_000_000;
|
||
|
int successful_attempts = 0;
|
||
|
|
||
|
for (int i = 0; i < total_attempts; i++) {
|
||
|
int a = ThreadLocalRandom.current().nextInt(256);
|
||
|
int b = ThreadLocalRandom.current().nextInt(256);
|
||
|
int c = ThreadLocalRandom.current().nextInt(256);
|
||
|
|
||
|
if (a + b + c > 300) {
|
||
|
successful_attempts++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
System.out.println("Iterations: " + total_attempts);
|
||
|
System.out.println("Valid sums: " + successful_attempts);
|
||
|
System.out.println("Probability: " + (float) successful_attempts / total_attempts);
|
||
|
}
|
||
|
}
|