Guest User

Untitled

a guest
Nov 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. package math5040;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class Rencontre2 {
  6.  
  7. public static void main(String[] args) {
  8. int[] unshuffled;
  9. unshuffled = new int[104];
  10. int[] shuffled;
  11. shuffled = new int[104];
  12. int count1 = 1;
  13. int count2 = 0;
  14.  
  15. for(int n = 0; n <= 103; n++) {
  16. unshuffled[n] = count1;
  17. shuffled[n] = count1;
  18. count1++;
  19. }
  20. System.out.println(Arrays.toString(unshuffled));
  21. System.out.println("\n");
  22.  
  23. for(int p = 1; p<=100000000; p++) {
  24. for(int k = 103; k >= 0; k--) {
  25. int j = (int)(k*Math.random()+1);
  26. int temp = shuffled[j];
  27. shuffled[j] = shuffled[k];
  28. shuffled[k] = temp;
  29. }
  30. System.out.println(Arrays.toString(shuffled));
  31. System.out.println("\n");
  32. for(int t = 0; t <= 103; t++) {
  33. if (unshuffled[t] == shuffled[t]) {
  34. count2++;
  35. break;
  36.  
  37. }
  38. }
  39.  
  40. }
  41. System.out.println("The sample size is 100000000");
  42. System.out.println("The number of recontres is " + count2);
  43. System.out.println("The probability of a recontre is " + count2 / 100000000);
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment