Skip to content

Instantly share code, notes, and snippets.

@ryuichimatsumoto-single
Last active January 11, 2016 11:36
Show Gist options
  • Select an option

  • Save ryuichimatsumoto-single/b019343bf9f2adc00b7b to your computer and use it in GitHub Desktop.

Select an option

Save ryuichimatsumoto-single/b019343bf9f2adc00b7b to your computer and use it in GitHub Desktop.
サイコロをn回振った時の出目をシュミレーション(A roll of the dice)
# coding: UTF-8
# サイコロを100回振った時の出目をシュミレーション(モンテカルロ法)
# 乱数は1〜6が同様に出る乱数(恐らく一様乱数)を使用
# 詳細は「http://qiita.com/yubais/items/bf9ce0a8fefdcc0b0c97」
import numpy as np
N= 100 #サイコロを振る回数
list = np.arange(N)
num = np.zeros(7)
for n in range(0,N):
#ここが計測手法f(X)の部分(1〜6の出目を生成)
list[n] = np.random.randint(1,7)
for m in range(0,7):
if m == list[n]:
num[m] = num[m] + 1#出目の回数をここでカウント
print list #100回の出目を出力
print num #出目が何回出たか出力
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment