Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Card shuffling
Replies: 7   Last Post: Jul 31, 2012 10:33 AM

 Messages: [ Previous | Next ]
 Mok-Kong Shen Posts: 629 Registered: 12/8/04
Re: Card shuffling
Posted: Jul 31, 2012 9:25 AM

Many thanks to all who have followed up. As I wrote in a 2nd post,
I have done some experiments. I found a presumably not too bad,
though I guess yet sub-optimal, scheme as follow:

Let n be the length of the list to be permuted and kn be a point of
division of the list into two sections. One applies riffle shuffle
to each section and then reverse the ordering of the whole.

It seems to me that, if kn is (randomly chosen and) located in the
middle half of the list, then the permutation effected is a sufficiently
"random" one in some sense.

Perhaps someone could give hints on improvements or provide a similar
but better scheme. For those who like to try out mine, I am attaching
a Python code below.

M. K. Shen

-----------------------------------------------------------

def makecards(n):
cards=[]
for i in range(n):
cards+=[i]
return(cards)

def riffle(cards,n):
newcards=[]
nh=n//2
for i in range(nh):
newcards=newcards+[cards[nh+i]]+[cards[i]]
if nh*2<n:
newcards+=[cards[n-1]]
return(newcards)

def newshuffle(cards,kn,n):
newcards=riffle(cards[0:kn],kn)+riffle(cards[kn:n],n-kn)
newcards.reverse()
return(newcards)

# example:

n=52
cards=makecards(n)
kn=18
newcards=newshuffle(cards,kn,n)
print(newcards)

Date Subject Author
7/30/12 Mok-Kong Shen
7/30/12 Scott Berg
7/31/12 Mok-Kong Shen
7/31/12 Scott Berg
7/31/12 KBH
7/31/12 LudovicoVan
7/31/12 Ben Bacarisse
7/31/12 Mok-Kong Shen