Symbulate Documentation

Cards, coins, and dice

Many probabilistic situations involving physical objects like cards, coins, and dice can be specified with BoxModel.

Be sure to import Symbulate using the following commands.

In [1]:
from symbulate import *
%matplotlib inline

Example. Rolling a fair n-sided die (with n=6).

In [2]:
n = 6
die = list(range(1, n+1))
P = BoxModel(die)
RV(P).sim(10000).plot()

Example. Flipping a fair coin twice and recording the results in sequence.

In [3]:
P = BoxModel(['H', 'T'], size=2, order_matters=True)
P.sim(10000).tabulate(normalize=True)
Out[3]:
Outcome Value
('H', 'H')0.2518
('H', 'T')0.2457
('T', 'H')0.2503
('T', 'T')0.2522
Total1.0

Example. Unequally likely outcomes on a colored "spinner".

In [4]:
P = BoxModel(['orange', 'brown', 'yellow'], probs=[0.5, 0.25, 0.25])
P.sim(10000).tabulate(normalize = True)
Out[4]:
Outcome Value
brown0.2458
orange0.5065
yellow0.2477
Total1.0

DeckOfCards() is a special case of BoxModel for drawing from a standard deck of 52 cards. By default replace=False.

Example. Simulated hands of 5 cards each.

In [5]:
DeckOfCards(size=5).sim(3)
Out[5]:
Index Result
0((2, 'Clubs'), (4, 'Clubs'), ('A', 'Diamonds'), ('Q', 'Spades'), (3, 'Hearts'))
1((7, 'Hearts'), ('J', 'Spades'), (5, 'Hearts'), ('A', 'Diamonds'), (5, 'Spades'))
2((2, 'Clubs'), ('Q', 'Spades'), ('A', 'Diamonds'), ('K', 'Spades'), (2, 'Hearts'))
In [ ]: