Python3 uniform() 函数
Python 3 教程
· 2019-02-05 16:27:48
描述
uniform() 方法将随机生成下一个实数,它在[x,y]范围内。
语法
以下是 uniform() 方法的语法:
import random random.uniform(x, y)
注意:uniform()是不能直接访问的,需要导入 random 模块,然后通过 random 静态对象调用该方法。
参数
- x -- 随机数的最小值。
- y -- 随机数的最大值。
返回值
返回一个浮点数。
实例
以下展示了使用 uniform() 方法的实例:
#!/usr/bin/python3
import random
print ("uniform(5, 10) 的随机浮点数 : ", random.uniform(5, 10))
print ("uniform(7, 14) 的随机浮点数 : ", random.uniform(7, 14))
以上实例运行后输出结果为:
uniform(5, 10) 的随机浮点数 : 7.054602800254241 uniform(7, 14) 的随机浮点数 : 12.552229882744296
点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html
Visual Thinking
Colin Ware / Morgan Kaufmann / 2008-4-18 / USD 49.95
Increasingly, designers need to present information in ways that aid their audiences thinking process. Fortunately, results from the relatively new science of human visual perception provide valuable ......一起来看看 《Visual Thinking》 这本书的介绍吧!