[英]Is random.random() the same as random.uniform()?
What is the difference between python's random.random()
method and random.uniform()
method? python的
random.random()
方法和random.uniform()
方法有什么random.uniform()
?
Are the result from random.random()
not uniformly distributed? 是否来自
random.random()
的结果分布不均匀?
import random
print(random.random() * 10)
print(random.uniform(0,10))
According to documentation , random.random()
returns a number in the range [0, 1.0), when random.uniform(a,b)
returns a number in range [a,b] or [a,b), depending on floating-point rounding in equation a + (ba) * random()
. 根据文档 ,
random.random()
返回范围为[ random.uniform(a,b)
的数字,而random.uniform(a,b)
返回范围为[a,b]或[a,b)的数字,具体取决于浮点数方程a + (ba) * random()
小数点舍入。
So both print(random.random() * 10)
and print(random.uniform(0,10))
can give you the same distribution. 因此,
print(random.random() * 10)
和print(random.uniform(0,10))
都可以提供相同的分布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.