Dados de 6 faces (d6)


In [1]:
from random import randint
from collections import Counter

lances = 10000

ct = Counter()
for _ in range(lances):
    ct[randint(1, 6)] += 1
    
ct


Out[1]:
Counter({1: 1653, 2: 1674, 3: 1661, 4: 1650, 5: 1655, 6: 1707})

In [2]:
categorias, contagens = zip(*sorted(ct.items()))
categorias, contagens


Out[2]:
((1, 2, 3, 4, 5, 6), (1653, 1674, 1661, 1650, 1655, 1707))

In [3]:
porcentagens = [c/lances * 100 for c in contagens]

In [4]:
%matplotlib inline
import matplotlib.pyplot as plt

plt.figure()
plt.bar(categorias, porcentagens)
plt.axhline(1/6 * 100, color='r')
plt.ylabel('%')
plt.xlabel('resultados d6')


Out[4]:
<matplotlib.text.Text at 0x10b47efd0>

Dois dados de 6 faces (2d6)


In [5]:
lances = 10000

ct = Counter()
for _ in range(lances):
    ct[randint(1, 6) + randint(1, 6)] += 1

In [6]:
import numpy as np
categorias, contagens = zip(*sorted(ct.items()))
porcentagens = [c/lances * 100 for c in contagens]
categorias = np.asarray(categorias)

In [7]:
plt.figure()
plt.bar(categorias, porcentagens)
plt.xticks(categorias + 0.5, categorias)
plt.xlim(min(categorias), max(categorias)+1)
plt.ylabel('%')
plt.xlabel('resultados d6+d6')


Out[7]:
<matplotlib.text.Text at 0x10b485630>