Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package math5040;
- import java.util.Arrays;
- public class Rencontre2 {
- public static void main(String[] args) {
- int[] unshuffled;
- unshuffled = new int[104];
- int[] shuffled;
- shuffled = new int[104];
- int count1 = 1;
- int count2 = 0;
- for(int n = 0; n <= 103; n++) {
- unshuffled[n] = count1;
- shuffled[n] = count1;
- count1++;
- }
- System.out.println(Arrays.toString(unshuffled));
- System.out.println("\n");
- for(int p = 1; p<=100000000; p++) {
- for(int k = 103; k >= 0; k--) {
- int j = (int)(k*Math.random()+1);
- int temp = shuffled[j];
- shuffled[j] = shuffled[k];
- shuffled[k] = temp;
- }
- System.out.println(Arrays.toString(shuffled));
- System.out.println("\n");
- for(int t = 0; t <= 103; t++) {
- if (unshuffled[t] == shuffled[t]) {
- count2++;
- break;
- }
- }
- }
- System.out.println("The sample size is 100000000");
- System.out.println("The number of recontres is " + count2);
- System.out.println("The probability of a recontre is " + count2 / 100000000);
- }
- }
Add Comment
Please, Sign In to add comment