play/notebooks/rolldice.ipynb

102 lines
7.6 KiB
Plaintext
Raw Normal View History

{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import scipy.stats"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"res = [int(os.popen('rolldice d20').read()) for i in range(10000)]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([541., 487., 471., 503., 531., 517., 489., 479., 490., 498., 505.,\n",
" 503., 488., 484., 515., 478., 522., 476., 533., 490.]),\n",
" array([ 1. , 1.95, 2.9 , 3.85, 4.8 , 5.75, 6.7 , 7.65, 8.6 ,\n",
" 9.55, 10.5 , 11.45, 12.4 , 13.35, 14.3 , 15.25, 16.2 , 17.15,\n",
" 18.1 , 19.05, 20. ]),\n",
" <a list of 20 Patch objects>)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAD8pJREFUeJzt3X+MpVV9x/H3pyzYRo3Lj+12u7txtZI29A+VbOharaHSUkDj0kYJxpQtbrIxwURjG93WxNqkf0CbSkvT0GyFuBiqUJWysVjdIsb0D6gDwgKiZSAQdrOwIyBoiG3Rb/+4Z9vLOLNzh5k7d/bwfiU39zznnGee7zz78Jlnztx7SVUhSerXz0y6AEnSeBn0ktQ5g16SOmfQS1LnDHpJ6pxBL0mdM+glqXMGvSR1zqCXpM6tmXQBAKeddlpt2bJl0mVI0nHlzjvv/F5VrVto3qoI+i1btjA1NTXpMiTpu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M4Z9JLUOYNekjpn0EtS5wx6SeqcQS9JnTPoJalzBr0kdc6gl6TOGfSS1DmDXpI6Z9BLUucMeknqnEEvSZ0z6CWpcwa9JHXOoJekzhn0ktQ5g16SOmfQS1LnDHpJ6txYgj7JeUm+m2Q6ye5xHEOSNJplD/okJwB/B5wPnAG8J8kZy30cSdJoxnFHfxYwXVUPV9V/A58Dto/hOJKkEYwj6DcCjw1tH2x9kqQJWDOpAyfZBexqmz9M8t1J1bKA04DvTbqIY7C+pVnt9cHqr9H6liBXLKm+V48yaRxBfwjYPLS9qfW9QFXtAfaM4fjLKslUVW2ddB3zsb6lWe31weqv0fqWZiXqG8fSzTeB05O8JslJwMXAvjEcR5I
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(res, bins=20)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Power_divergenceResult(statistic=31984.521923755903, pvalue=0.0)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"scipy.stats.chisquare(res)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}