Riffle Shuffle

Author

Eric W. Weisstein
March 16, 2006

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Games/RiffleShuffle.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/RiffleShuffle.html.

©2006 Wolfram Research, Inc. except for portions noted otherwise

Code

For odd n, need

Partition[Range[n],n/2,n/2,1,{}]

But for even n,

Shuffle[l_List]:=Transpose[Partition[l,Length[l]/2]]/;EvenQ[ Length[l]]
Shuffle[n_Integer]:=Shuffle[Range[n]]

InShuffle[l_List]:=Flatten[Reverse/@Shuffle[l]]/;EvenQ[ Length[l]]
OutShuffle[l_List]:=Flatten[Shuffle[l]]/;EvenQ[ Length[l]]

Even

v5

Shuffle[8]

v6

Riffle@@Partition[Range[8],4]

...wrong...; missing trailing 8

Minimum number of riffle shuffles needed

3Log[2,52]/2.