Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int countOnes = 0;
- int countTwos = 0;
- int countThrees = 0;
- for (int i = 0; i < 10_000; i++) {
- switch(drawRandomNumber()) {
- case 1:
- countOnes++;
- break;
- case 2:
- countTwos++;
- break;
- case 3:
- countThrees++;
- }
- }
- NumberFormat nf = NumberFormat.getPercentInstance(Locale.ENGLISH);
- System.out.println("TEST_1 (10_000 loops):");
- System.out.println("1 returned: " + nf.format(countOnes/10_000.0));
- System.out.println("2 returned: " +nf.format(countTwos/10_000.0));
- System.out.println("3 returned: " +nf.format(countThrees/10_000.0));
- countOnes = 0;
- countTwos = 0;
- countThrees = 0;
- for (int i = 0; i < 60_000; i++) {
- switch(drawRandomNumber()) {
- case 1:
- countOnes++;
- break;
- case 2:
- countTwos++;
- break;
- case 3:
- countThrees++;
- }
- }
- System.out.println("TEST_2 (60_000 loops):");
- System.out.println("1 returned: " + nf.format(countOnes/60_000.0));
- System.out.println("2 returned: " +nf.format(countTwos/60_000.0));
- System.out.println("3 returned: " +nf.format(countThrees/60_000.0));
- }
- public static int drawRandomNumber(){
- double x = (Math.random()*((100 - 0)+1))+0;
- if (x < 20)
- return 1;
- else if (x < 50)
- return 2;
- else
- return 3;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement