Advertisement
Guest User

Cards Simulation

a guest
Sep 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.25 KB | None | 0 0
  1. samplesize = 10000;
  2. confidence = 0.95;
  3.  
  4. decksize = 34;
  5. nbplayers = 11;
  6. drawsize = 5;
  7.  
  8. groupmatches = zeros(samplesize,1);
  9. individualmatches = zeros(samplesize,nbplayers);
  10. deck = (1:decksize)';
  11.  
  12.  
  13. for m = 1:samplesize
  14. hands = zeros(drawsize,nbplayers);
  15. for n = 1:nbplayers
  16.     hands(:,n) = datasample(deck,5,'Replace',false);
  17. end
  18. cardsdrawn = unique(hands);
  19. percardcount = histcounts(reshape(hands,nbplayers*drawsize,1),[cardsdrawn; (decksize+1)]);
  20. groupmatches(m) = sum(percardcount-1);
  21.  
  22. for n = 1:nbplayers
  23.     index = true(1,nbplayers);
  24.     index(n) = false;
  25.     individualmatches(m,n) = nnz(ismember(hands(:,n),hands(:,index)));
  26. end
  27.  
  28.  
  29. end
  30.  
  31. individualmatches = reshape(individualmatches,nbplayers*samplesize,1);
  32.  
  33. groupmatches_estimator = mean(groupmatches);
  34. groupmatches_error = std(groupmatches)/sqrt(length(groupmatches));
  35. individualmatches_estimator = mean(individualmatches);
  36. individualmatches_error = std(individualmatches)/sqrt(length(individualmatches));
  37.  
  38. Z = norminv(1 - 0.5*(1-confidence),0,1);
  39. groupmatches_interval = groupmatches_estimator + (Z*groupmatches_error).*[-1 1];
  40. individualmatches_interval = individualmatches_estimator + (Z*individualmatches_error).*[-1 1];
  41.  
  42. clearvars n index margin m cardsdrawn percardcount hands;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement