import random
def rollDie(): """returns a random int between 1 and 6"""
return random.choice([1,2,3,4,5,6])
def testRoll(n = 10): result = '' for i in range(n):
result = result + str(rollDie()) print(result)
三、三个关于概率的基本事实
1、在0-1之间
2、p和1-p的关系
3、相互独立
四、模拟摇骰子
def runSim(goal, numTrials, txt):
total = 0
for i in range(numTrials):
result = ''
for j in range(len(goal)):
result += str(rollDie())
if result == goal:
total += 1
print('Actual probability of',
Lec 4(Stochastic) and 5(Random Walks)一、世界是难以理解的不确定性是令人很不舒服的但确定性却通常是不适合的预测的不确定性二、随机过程import randomdef rollDie(): """returns a random int between 1 and 6""" return random.choice([1,2,3,4,5,...