Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math.independent

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Mok-Kong Shen

Posts: 518
Registered: 12/8/04
Re: Card shuffling
Posted: Jul 31, 2012 9:25 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


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)





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.