Shuffle test - an experiment

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]



Search WWW


As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.


Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 


We receive a few cents from each purchase.  Thanks


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa 365 Puzzlers  Calendar 2017

Mensa 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)


Feedback:  Send an e-mail with your comments about this program (or anything else).

Search only



Problem Description

{A viewer recently pointed out that the existing shuffle procedure used in DFF programs is statistically invalid. Shuffling consists of exchanging each card in a deck one time with another randomly selected card. My current version selects the random card from anywhere in the deck. The proposed "correct" procedure selects the random card only from those that have not yet been exchanged.

Being of curious mind, I had to convince myself that it makes a difference.  The bottom line is that it does make a difference for a single shuffle of and un-shuffled deck. If the deck is shuffled 3 or 4 times, the methods are equally random.


Background & Techniques

The program starts with an ordered decked and shuffles a specified number of times. The the long run, for a valid methodology, the card value for any position in the deck is equally likely to be any card, so the expected value of of the card in any position is the mean value of all the cards. After each shuffle, we'll plot the mean card value for each card position vs. the positions and should see the chart move toward a straight line at the mean card value.  We'll also display a measure of how the observed mean values vary from the
expected means.

The sum of the squared differences between the observed mean values and the expected value across all card positions. This should approach zero the number of shuffles increases, and does for the corrected procedure.

Most of the ideas for this program came from an old Pascal program to illustrate his excellent discussion of right and wrong ways to shuffle; Check

I'm still trying to rationalize the observed results. The old method, on average,  is slightly more likely to leave cards that start toward the end of the deck still toward the end of the deck after shuffling. 

Running/Exploring the Program 


Original Date: August 21,2006

Modified: July 29, 2017



  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.