C Shuffle

4 views
Skip to first unread message

jondavidjohn

unread,
Jan 23, 2012, 11:09:30 AM1/23/12
to PySGF
Got an itch to learn some C over the weekend and converted the
shuffling function we wrote for the magic_utilities project to a
Python C Extension module. So now it's substantially faster... Also
this might be useful for anyone else interested in writing C modules
for use in python as an example...

https://github.com/jondavidjohn/Card-Shuffle-for-Python

For example, shuffling a list of 1000 items 6 times

Python -> 1.078 seconds to execute 130 times
C Extension -> 0.05 seconds to execute 130 times

Matt Thompson

unread,
Jan 23, 2012, 1:54:14 PM1/23/12
to PySGF
Is there a reason you didn't just use http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
?

jondavidjohn

unread,
Jan 23, 2012, 2:02:44 PM1/23/12
to PySGF
The goal was not to just create a random unbiased permutation of a
List, but to produce a simulated Riffle Shuffle...

http://en.wikipedia.org/wiki/Shuffling#Riffle

Which has an element of imperfection(random-ness), but is in no way
unbiased or completely random.  The README on the repo lists the
imperfect considerations we took into account...

On Jan 23, 12:54 pm, Matt Thompson <chameleona...@gmail.com> wrote:
> Is there a reason you didn't just usehttp://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

jondavidjohn

unread,
Jan 23, 2012, 2:03:21 PM1/23/12
to PySGF
And on top of that, it was just more fun to solve it ourselves.

Scott Blevins

unread,
Jan 23, 2012, 2:04:11 PM1/23/12
to py...@googlegroups.com
Looks good Jonathan! Very cool.

Yeah Matt, it is definitely an algorithm that might have been useful
but we really wanted to actually simulate the "clumping" effect that
happens when someone actually shuffles a deck of cards. I don't think
the Fisher Yates takes that into account.

We might use it somewhere else... perhaps for the duel portion of the site... :)

Scott Blevins

unread,
Jan 23, 2012, 2:05:33 PM1/23/12
to py...@googlegroups.com
Well said and bravo! :) I think this whole project has been fun for
me. I can't wait to get in there and do more styling, cleanup, and
framework for the rest of our upgrades. I am super looking forward to
the deck builder.
Reply all
Reply to author
Forward
0 new messages