Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes this simple shuffling algorithm return a randomly shuffled deck of playing cards?
    primarykey
    data
    text
    <p>You have a list of 52 cards where the position of the cards in that list does not move. You have a second list of card positions. At first, the position list is the same as the first list.</p> <ol> <li><p>Iterate through the first list. </p></li> <li><p>For each card in the first list, generate a number from 1 to 52. Swap its position in the second list with the card in that position.</p></li> </ol> <p>Does a bias exist? Why?</p> <p>Update: Never one to believe pure math or logic, I decided to implement this myself. Here are the percent chance of the 5th card (position-wise) to be each number from 1 to 52:</p> <pre><code>1. 1.9346% 2. 1.9011% 3. 1.8513% 4. 1.8634% 5. 1.8561% 6. 1.8382% 7. 2.5086% 8. 2.4528% 9. 2.4552% 10. 2.3772% 11. 2.3658% 12. 2.3264% 13. 2.3375% 14. 2.287% 15. 2.2627% 16. 2.2151% 17. 2.1846% 18. 2.1776% 19. 2.1441% 20. 2.1103% 21. 2.084% 22. 2.0505% 23. 2.0441% 24. 2.0201% 25. 1.972% 26. 1.9568% 27. 1.9477% 28. 1.9429% 29. 1.9094% 30. 1.8714% 31. 1.8463% 32. 1.8253% 33. 1.8308% 34. 1.8005% 35. 1.7633% 36. 1.7634% 37. 1.769% 38. 1.7269% 39. 1.705% 40. 1.6858% 41. 1.6657% 42. 1.6491% 43. 1.6403% 44. 1.6189% 45. 1.6204% 46. 1.5953% 47. 1.5872% 48. 1.5632% 49. 1.5402% 50. 1.5347% 51. 1.5191% 52. 1.5011% </code></pre> <p>As you can see, quite un-random. I'd love a mathematician to prove why the 5th card is more likely to be a 7 than anything else, but I'm guessing it has to do with the fact that early cards, like 7, have more opportunities to swap -- which is exactly what the right algorithm prevents, it only lets cards swap once.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload