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.
from symbulate import *
%matplotlib inline
Example. Rolling a fair n-sided die (with n=6).
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.
P = BoxModel(['H', 'T'], size=2, order_matters=True)
P.sim(10000).tabulate(normalize=True)
Example. Unequally likely outcomes on a colored "spinner".
P = BoxModel(['orange', 'brown', 'yellow'], probs=[0.5, 0.25, 0.25])
P.sim(10000).tabulate(normalize = True)
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.
DeckOfCards(size=5).sim(3)