首页 > 解决方案 > python - 使用正常法则生成随机流量

问题描述

我正在寻找使用正常定律来生成伪随机事件。

我想要的是:

你会如何在 python 中做到这一点?我自己也不知道:(

谢谢

标签: pythonprobability

解决方案


reduce在非空集上使用;偷基本and_操作做你的路口。

from functools import reduce
from operator import and_

# Start with an empty set
a = set()
b = {1, 4, 8, 9}
c = {1, 5, 10, 15}
d = {1, 100, 200}
e = {1, 2, 3}

my_sets = [a, b, c, d, e]

print(reduce(and_, [q for q in my_sets if q]))

输出:

{1}

推荐阅读