jvm延迟偏向
Here, we will be simulating the occurrence coin face i.e. H - HEAD, T - TAIL. Simply we are going to use an inbuilt library called as random to call a random value from given set and thereby we can stimulate the occurrence value by storing the occurrence in the list ls of length 2 representing each face of the coin as ls[] represents the occurrence of:
在这里,我们将模拟出现的硬币面,即H-HEAD,T-TAIL 。 简单地讲,我们将使用一个称为random的内置库从给定集合中调用随机值,从而可以通过将出现的事件存储在长度为2的列表ls中 (表示硬币的每个面为ls []表示)来刺激出现值发生:
Here, we will be stimulating the occurrence of each dice face i.e. 1, 2, 3, 4, 4, 4, 5, 6, 6, 6, 6. Simply we are going to use an inbuilt library called as random to call a random value from given set and thereby we can stimulate the occurrence value by storing the occurrence in the list ls of length 6 representing each face of the dice as ls[4] represents the occurrence of face 5.
在这里,我们将刺激每个骰子面的出现,即1、2、3、4、4、4、5、6、6、6、6。简单地说,我们将使用一个称为random的内置库来调用a给定集合中的随机值,因此我们可以通过将出现次数存储在代表骰子每个面的长度为6的列表ls中来刺激出现值,因为ls [4]代表面5的出现。
ls[0] - coin(H)ls[1] - coin(T)
Then using the library pylab, we can plot the value of each occurrence and can stimulate it.
然后,使用库pylab ,我们可以绘制每个事件的值并进行刺激。
The deviation is clear that each of the faces i.e. heads and tails have an unequal probability of occurrence.
这种偏差很明显,每个面(即头和尾)的出现概率均不相等。
Program:
程序:
import random
import pylab as py
def flip():
return random.choice(['H','H','H','T','T','H','T'])
ls = [0,0]
chance = [104, 203, 302, 401, 505, 646, 756, 855, 985, 4565, 6565]
for n in chance:
for k in range(n):
scr = flip()
if scr == 'H':
ls[0] = ls[0] + 4/4
else:
ls[1] = ls[1] + 4/4
py.figure()
py.plot(['H','T'], ls, 'bo')
py.ylim(0,12300)
print("HEADS: ", ls[0])
print("TAILS: ", ls[1])
Output
输出量
翻译自: https://www.includehelp.com/python/program-for-biased-coin-flipping-simulation.aspx
jvm延迟偏向