Advertisement
Guest User

this is probably inoptimal, but

a guest
Oct 27th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. public static void main(String[] args) {
  2. int sum = 0;
  3. int a = 37;
  4. int trials = 10000;
  5. int[] list = new int[trials];
  6. for (int i = 0;i<trials;i++){
  7. int[] check = new int[a];
  8. int times = 0;
  9. boolean done = false;
  10. for (int j = 0;j<check.length;j++){
  11. check[j] = j+1;
  12. }
  13. while (!done){
  14. int prng = (int) (Math.random()*check.length);
  15. check[prng] = 0;
  16. times++;
  17. done = true;
  18. for (int j = 0;j<check.length;j++){
  19. if (check[j] != 0) done = false;
  20. }
  21. }
  22. sum += times;
  23. list[i] = times;
  24. }
  25. double average = sum/trials;
  26. System.out.println(average);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement