title: How to solve "the birthday paradox" in java without using nested loop?
body: <p>I have tried the problem with nested loop, but how can I solve it without using nested loops and within the same class file. The Question is to find the probability of two people having the same birthday in a group. And it should produce the following <strong>output : In a group of 5 people and 10000 simulations, the probability is 2.71%.</strong> Note: using arraylist or hashmap is possible. But I don't know how. Thank you</p>
  
  <pre><code>public void process() {
      int groupSize = System.out.getSize();
      int simulationCount = System.out.getCount();
  
      if (groupSize &lt; 2 || groupSize &gt; 365) {
          System.out.makeAlertToast("Group Size must be in the range 2-365.");
          return;
      }
      if (simulationCount &lt;= 0) {
          System.out.makeAlertToast("Simulation Count must be positive.");
          return;
      }
  
      double percent = calculate(groupSize, simulationCount);
  
      // report results
      System.out.println("For a group of " + groupSize + " people, the     percentage");
      System.out.println("of times that two people share the same birthday        is");
      System.out.println(String.format("%.2f%% of the time.", percent));
  
  }
  
  
  public double calculate(int size, int count) {
      int numTrialSuccesses = 0;
  
      // Repeat and count.
      for (int n=0; n &lt; count; n++) {
          Random rand = new Random(n);
          // Generate birthdays (random array)
          int[] birthdays = new int [size];
          for (int i=0; i &lt;size; i++) {
              birthdays[i] = rand.nextInt (365);
          }
  
          // Check if any two match.
          boolean matchExists = false;
          for (int i=0; i &lt; size; i++) {
              for (int j=0; j &lt; size; j++) {
                  if ( (i != j) &amp;&amp; (birthdays[i] == birthdays[j]) ) {
                      // Note: musn't forget the i!=j test above!
                      matchExists = true;
                      if (matchExists) break;
                  }
              }
          }
  
          if (matchExists) {
              numTrialSuccesses ++;
          }
  
      } //end-for-trials
  
      double prob = ((double) numTrialSuccesses *100)/ (double) count;
      return prob ;
  
  }
  
  }
  </code></pre>