使用伪随机生成器从 python 中的列表中随机选择一个元素,这应该有 50% 的时间发生
randomly pick an element from a list in python using pseudo random generator which should happen 50 percent of time
我有一个列表,其中包含某些 elements.For 示例事件 =["head","tail"]。应使用伪随机 generator.This 随机事件随机选取每个元素time.Use 应该出现大约 50% 的某种伪随机数生成器,但以一种我们可以重复测试或序列的方式进行,如果测试中的某些内容失败,我们可以重复 happened.This 应在 python
中实施
import random as rnd
coin=["h","t"]
seed=10
rnd.seed(seed)
for i in range(100):
print coin[rnd.randint(0,1)]
这是你想要的吗?请在以后的问题中更具体
我相信你的意思
make this in a way that we can repeat the test or the sequence that way if something in the test fails, we can repeat what happened
是种子的使用。种子本质上是导致伪随机数生成器始终产生相同结果的字符串,前提是相同的种子。
import random
random.seed('abcd')
coin = ['heads', 'tails']
number_of_tests = 100
for i in range(number_of_tests):
print(random.choice(coin))
任何时候你想用相同的结果重复测试,只需调用
random.seed('abcd')
再次。
我有一个列表,其中包含某些 elements.For 示例事件 =["head","tail"]。应使用伪随机 generator.This 随机事件随机选取每个元素time.Use 应该出现大约 50% 的某种伪随机数生成器,但以一种我们可以重复测试或序列的方式进行,如果测试中的某些内容失败,我们可以重复 happened.This 应在 python
中实施import random as rnd
coin=["h","t"]
seed=10
rnd.seed(seed)
for i in range(100):
print coin[rnd.randint(0,1)]
这是你想要的吗?请在以后的问题中更具体
我相信你的意思
make this in a way that we can repeat the test or the sequence that way if something in the test fails, we can repeat what happened
是种子的使用。种子本质上是导致伪随机数生成器始终产生相同结果的字符串,前提是相同的种子。
import random
random.seed('abcd')
coin = ['heads', 'tails']
number_of_tests = 100
for i in range(number_of_tests):
print(random.choice(coin))
任何时候你想用相同的结果重复测试,只需调用
random.seed('abcd')
再次。