Skip to main content

logo

docsPyPI - VersionTest

shuffle-kit is a Python package for modelling and analyzing playing card shuffles.

It implements several mathematical models of commonly used shuffles that can be composed into complex sequences.

In addition, several utility functions are provided to faciliate analyzing the various shuffle models.

Installation

Dependencies

shuffle-kit requires:

  • Python (>= 3.11)
  • Numpy (>= 1.26.3)

User installation

The easiest way to install shuffle-kit is via pip:

pip install shuffle-kit

Examples

Basic example of using shuffle-kit

from shuffl import gsr, strip, cut, sequence, simulate, Deck
from itertools import accumulate

# Creates a list of integers from 1..52, representing a
# standard deck of 52 cards
deck = Deck(range(1,53))

# Creates a riffle, riffle, strip, riffle, cut shuffle sequence
# with the Gilbert-Shannon-Reeds model for riffle shuffling
shuffle = sequence([gsr, gsr, strip, gsr, cut])

# Simulate the shuffle a 1000 times. For each simulation, the
# deck is reset to the initial order
result = simulate(shuffle, deck, 1000)

# Compute the empirical cumulative density function of the
# original top card, i.e., "1"
ecdf = list(accumulate(result.probability[0]))

# Print the probability that the original top card ("1") is
# found within the top ten cards after shuffling
print(f"Probability of finding '1' within the top ten cards: {ecdf[9]:.2}")

Simulating a guessing game

Here we play a round of the guessing game described in Bayer and Diaconis (1992). Consider a shuffled deck of 52 cards, face down on the table. The task is to guess the top card. After each guess, the top card is turned over and discarded.

If the deck is perfectly shuffled the average number of correct guesses is around 4.5. However, if the deck is riffle shuffled k times, then there exists a conjectural optimal strategy that achives a higher number of correct guesses depending on k.

from shuffl.games import guessing_game
from shuffl import gsr, Deck, sequence

# Creates a list of integers from 1..52, representing a
# standard deck of 52 cards
deck = Deck(range(1, 53))

# Creates a sequence of two riffle shuffles following
# the Gilbert-Shannon-Reeds model
shuffle = sequence([gsr, gsr])

# Run a simulation of the guessing game described in
# Bayer D., Diaconis P. (1992). Trailing the dovetail shuffle to its lair.
# The Annals of Applied Probability, Vol. 2, No. 2, 294-313
correct_guess = guessing_game(deck, shuffle)

# Print the number of correct guesses. On average this should
# be around 19.
print(f"Number of correct guesses: {correct_guess}")

Metadata

Release files for shuffle-kit 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shuffle-kit 0.1.3
File Size Uploaded
shuffle_kit-0.1.3.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shuffle-kit 0.1.3
File Interpreter ABI Platform
shuffle_kit-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 14.1 kB

Release files / shuffle_kit-0.1.3.tar.gz

Download URL shuffle_kit-0.1.3.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bbf08d14243ff5d14c8ffdfdf3f19676a4a4870162c791535ba2d9cefb7932b7
BLAKE2b-256 checksum
How to use checksums
9a508f9f3f78a829485dd1802dbab82add7adb2da5aec1f6a28c7307e77a8e0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.4 Windows/10

Release files / shuffle_kit-0.1.3-py3-none-any.whl

Download URL shuffle_kit-0.1.3-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ccaa65df1b1f64909749eb5e0101c213a47739214d385d44e33a15dfcf8690c
BLAKE2b-256 checksum
How to use checksums
e676b2f73202fdca1b18a21b5d7649e5a769ebae1881e9977a49c437c326ae56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.4 Windows/10

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page