Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在 Python 中模拟一个游戏,考虑到这些概率,我该如何对其进行编程,以便它给我一个列表,列出每个人从总共 10 场游戏中获胜的次数?
A 获胜的概率是 0.416667 B 获胜的概率是 0.583333
这样的事情应该这样做:
for x in range(0, 9): if expression(random.uniform(0.0, 1.0) < 0.416667): print "A wins" else: print "B wins"
如果它必须非常精确,这不是一个好主意,因为边界没有正确处理。