This thread is an institution, there is no way I can let it die with the WotC Forums.
First, the
[O]fficial explaination of how the MTGO shuffler works, originally provided by Chris Green, president of Leaping Lizards (who developed the thing), preserved by muriban and passed on to Vitalogy1994 who posted it in the last incarnation of this thread:
ChrisG wrote:
MTGO's Shuffle Algorithm...get the technical low down... March 15, 2002 by Chris Green A technical description of Magic Online's shuffler and random number generator. The core random number generator used is "Algorithm A", from Knuth's "Art of Computer Programming", sec 3.2.2. This is a fast, easy to implement random number generator. Knuth states that it has "consistently produced reliable results, in extensive tests since its invention in 1958." I first implemented this generator in 6502 assembly code in 1981 or so, and it has never failed me. The implementation of this generator used in our libraries uses the standard constants (24,55). Because this is somewhat fewer than the number of bits required to produce all possible hands, it was augmented with another generator using the constants (33,68). This yields a total state size of 3936 bits. Both generators were combined so that the random number calls used in our library could still return the same sequence of numbers when initiated by our old programs (never know when we might have to rebuild a new version of Centipede3D for the Dreamcast :-) ). In MTGO, random numbers are initialized by the game servers. When a new game is started, the random number state is seeded via /dev/random, which uses hardware delays for a source of true random data. In addition, whenever a packet is received from a user by the game server, the lower order bits of the system CPU's clock cycle counter are added into the random state. Shuffling is performed by swapping every card in the deck with a random other card in the deck. This is algorithm "P" for shuffling from Knuth. The book contains a formal analysis of its randomness. The 32 bit random values returned by the basic random number function are mapped into the appropriate range by fixed point multiplication. One of our programmers, Sergey, was not satisfied that the random number generator wasn't mana-screwing him, and so performed the following test: The shuffler has no idea what is a land and is not a land, so if there is any unnatural clumping of lands, it must be based upon the initial ordering of the deck. So he performed the following test: Create in memory a virtual deck of 20 "1"s, representing lands, and 40 "0"s representing non-lands. Put all the "lands" first and then all the "nonlands". Apply the shuffler. Perform the same test, except with lands and nonlands interleaved before shuffling. Perform each test multiple millions of times. After each test, count the sizes of land/non-land clusters and keep a running total of each. Compare the results from the millions of runs with the deck ordered with all lands together versus the interleaved one. The results were the same to within a minuscule fraction of a percent. In addition, he wished to verify that shuffling extra times would have no effect. If it did have an effect that would mean that the shuffle was insufficiently random. He performed this test and got the same statistics from one shuffle as from many.
We have no guarantee the shuffler is identical to the original incarnation of MTGO, but there also doesn't seem to be a reason they would change it.
The primary reasons people think the shuffler isn't random:Most people are under the misconception that a random distribution means an even distribution. Random distributions have natural clustering.
Experience doesn't match what they are used to in paper; there are many poor (human) shufflers out there. When confronted with *actual* randomness of the computer shuffler, they blame the computer instead of their own faulty shuffling practices. In reality these people have been unknowingly cheating for a long time.
People tend to remember significant events more vividly then normal occurrences. They remember the times when they were horrifically flooded but forget all the normal games in between.
Now, some required reading before you post if you want any hope of people caring what you say:Stats 101: Am I Shuffling Enough - Or Correctly, For That Matter? - A very good explaination of what a randomized deck *should* look like; it's far different than many think. [Provided by Vitalogy]
The
Wikipedia Entry on Knuth Shuffling. Here's a code snipet using the method [adapted from code posted by many]:
Code:
deck = new Card[n] ; an array of Card objects n long (syntax: first element is element zero)
do i=0,n-1
swap = Random(i,n-1) ; random integer between i and n-1 (inclusive) generated as described by ChrisG
temp = deck[swap] ; store the card to swap into current position for a moment
deck[swap] = deck[i] ; move the current card where the swapped card was
deck[i] = temp ; move the swapped card where the current card was delete(temp) ; cleanup
delete(swap) ; cleanup
end do
Actual OpenBSD code for a strong random number generator using hardware noise. Includes underlying theory [pointed out by slpalmer]
Article describing similar complaints in bridge since they switched to computer-generated deals 30+ years ago. Turns out (suprise!) people weren't shuffling correctly so their expectations were wildly different than should occur with truely random deals. Also discusses how many shuffles are necessary to randomize a deck. [Provided by me]
Math Magic Made Easy - Excel™ spreadsheet I created that computes various Magic math situations. One of the pages produces the probability of drawing so many cards of a certain type (listed as lands) out of N cards drawn from a deck of your choice. This should be useful if you want to try and disprove the shuffler by drawing a set number of cards from your deck instead of comparing the number of land clumps in the full deck as SCG does. [Shameless self-plug]
If you want to try and disprove the randomness of the shuffler, here are some things you MUST do:Use EVERY trial you do, don't pick-and-choose 'bad' ones and note them.
Run a BARE MINIMUM of 1000 trials. Hundreds of thousands would be better.
Read up on statistical confidence intervals and learn how to conduct a T-Test, Z-Test or similar.
Xtofyr recorded data for several thousand hands. The initial results appeared skewed and prompted more thorough testing by elf. These later tests show the shuffler to behave as expected. Unfortunately, the full discussion thread and results have been lost.
The probability for common MTG cases:Seven Cards (opening hand):
#land drawn|16/40|17/40|18/40|23/60|24/60|25/60
0|01.86%|01.31%|00.91%|02.67%|02.16%|01.74%
1|11.55%|09.20%|07.20%|13.84%|12.10%|10.51%
2|27.36%|24.55%|21.61%|28.56%|26.94%|25.22%
3|31.92%|32.30%|32.02%|30.29%|30.87%|31.18%
4|19.76%|22.61%|25.28%|17.82%|19.64%|21.44%
5|06.47%|08.40%|10.62%|05.80%|06.93%|08.19%
6|01.03%|01.53%|02.19%|00.97%|01.25%|01.60%
7|00.06%|00.10%|00.17%|00.06%|00.09%|00.12%
2-5|85.50%|87.85%|89.52%|82.46%|84.39%|86.02%Six Cards (mulligan):
# land drawn|16/40|17/40|18/40|23/60|24/60|25/60
0|03.51%|02.63%|01.97%|04.64%|03.89%|03.24%
1|17.72%|14.90%|12.35%|20.03%|18.07%|16.21%
2|33.22%|31.37%|29.16%|33.38%|32.47%|31.37%
3|29.53%|31.37%|32.74%|27.49%|28.87%|30.07%
4|13.09%|15.69%|18.42%|11.78%|13.37%|15.03%
5|02.73%|03.71%|04.91%|02.49%|03.07%|03.71%
6|00.21%|00.32%|00.48%|00.20%|00.27%|00.35%
2-4|75.84%|78.44%|80.31%|72.64%|74.71%|76.48%Eleven Cards (5th turn play/4th turn draw):
# land drawn| 16/40| 17/40| 18/40| 23/60| 24/60| 25/60
0|00.1080%|00.0585%|00.0305%|00.2495%|00.1753%|00.1217%
1|01.3574%|00.8413%|00.5035%|02.3378%|01.7801%|01.3392%
2|06.7869%|04.8074%|03.2920%|09.1842%|07.5820%|06.1810%
3|17.8157%|14.4222%|11.2870%|19.9518%|17.8719%|15.7958%
4|27.2476%|25.2389%|22.5739%|26.6024%|25.8834%|24.8220%
5|25.4310%|27.0205%|27.6531%|22.8266%|24.1578%|25.1644%
6|14.7232%|18.0137%|21.1465%|12.8399%|14.8064%|16.7763%
7|05.2583%|07.4493%|10.0697%|04.7247%|05.9490%|07.3445%
8|01.1268%|01.8623%|02.9149%|01.1117%|01.5323%|02.0656%
9|00.1366%|00.2660%|00.4858%|00.1588%|00.2404%|00.3547%
10|<0.0001%|00.0193%|00.0416%|00.0124%|00.0206%|00.0334%
11|<0.0001%|<0.0001%|<0.0001%|<0.0001%|<0.0001%|<0.0001%NB: booster/tournament packs are NOT random, nor are they intended to be. They are created using card listings called
print runs.
If there is anything important you think I missed, let me know.
Credits: Everyone who has contributed their time to the rational discussion of the shuffler in various threads over the years.
Edit (23 Nov 05 19:05 UTC): Added 'Sweet-spot' total probabilities (at least 2 lands + 2 spells in opening hand) and probabilities for a mulliganed hand.
Edit (10 Jul 06 05:53 UTC): Added link to data provided by Xtofyr and Elf.
Edit (18 Jan 08 20:10 UTC): Updated FAQ reference
Edit (15 Mar 10 19:50 UTC): Reformatted with html tags
Edit (26 Sep 15 18:47 UTC): Port to NGA Board