Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package livesPredictor;
- import java.util.ArrayList;
- import java.util.Random;
- public class LivesPredictor {
- static Random rnd;
- static double winProb = 0.3175;
- public static void main(String[] args) {
- rnd = new Random();
- ArrayList<Integer> lives = new ArrayList<Integer>();
- double p;
- for(int i=0; i<4; i++) lives.add(0); // 0 lives left, 1 life left, 2 lives left, 3 lives left; each start at 0
- for(int t=0; t<1000000; t++) {
- p = rnd.nextDouble();
- int l = 3;
- while(p > winProb && l > 0) {
- l--;
- p = rnd.nextDouble();
- }
- int count = lives.get(l);
- lives.set(l, count+1); // Increment lives left at end
- }
- for(int i=0; i<4; i++) {
- System.out.println("Times with " + i + " lives left: " + lives.get(i) + ".");
- }
- }
- }
Add Comment
Please, Sign In to add comment