在 python 中使用 random.random 生成随机样本
Generating random sample with random.random in python
我想使用 random.random 函数生成 100 个介于 0 和 1 之间的随机数的样本大小。
import random
sample = [random.random for x in range(100)]
例如,while print(len(sample))
给我 100,print(sample[1])
returns 只是对随机对象 () 的引用,而不是我想要的实际随机数。
为什么这对我不起作用?
可能是基本问题,但我找不到答案。
您没有调用方法:
[random.random() for x in range(100)]
^^
我想使用 random.random 函数生成 100 个介于 0 和 1 之间的随机数的样本大小。
import random
sample = [random.random for x in range(100)]
例如,while print(len(sample))
给我 100,print(sample[1])
returns 只是对随机对象 () 的引用,而不是我想要的实际随机数。
为什么这对我不起作用?
可能是基本问题,但我找不到答案。
您没有调用方法:
[random.random() for x in range(100)]
^^