Python中的random.uniform()函数教程与实例解析
2019-03-28 10:59
691 查看
random.uniform( ) 函数教程与实例解析
1. uniform( ) 函数说明
random.uniform(x, y)
方法将随机生成一个实数,它在 [x,y]
范围内。
2. uniform( ) 的语法与参数
2.1 语法
# _*_ coding: utf-8 _*_ import random random.uniform(x, y)
或
# _*_ coding: utf-8 _*_ from random import uniform uniform(x, y)
提示:uniform 包含在random库中,需要使用时需导入random库。
2.2 参数
- x -- 随机数的最小值,包含该值。
- y -- 随机数的最大值,不包含该值。
- 返回一个浮点数
3. 实例
例程:
# _*_ coding: utf-8 _*_ import random print("uniform(1 , 6) 的随机返回值为 : ", random.uniform(1 , 6)) print("uniform(10, 16) 的随机返回值为 : ", random.uniform(10, 16))
运行结果:
#uniform(1 , 6) 的随机返回值为 : 3.001161523486847
#uniform(10, 16) 的随机返回值为 : 13.70906147017741
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接
您可能感兴趣的文章:
相关文章推荐
- Python中zip()函数用法实例教程
- python中set()函数简介及实例解析
- Python中函数的用法实例教程
- Python中函数的用法实例教程
- Python中zip()函数用法实例教程
- Python中zip()函数用法实例教程
- CDays-2 习题一 (改进函数)及相关内容解析。Python 基础教程
- python元组操作实例解析
- python中的对象,方法,类,实例,函数用法分析
- Linux上安装Python的PIL和Pillow库处理图片的实例教程
- python 类,类实例及其它对象的内建函数
- Python callable()函数用法实例分析
- python 实例方法,类方法,静态方法,普通函数
- Android SAX解析实例教程
- Python字典,函数,全局变量代码解析
- Python中的对象,方法,类,实例,函数用法分析
- Learning Python:1. 生成器函数、列表解析与map,for循环的效率对比
- php urlencode()函数URL编码转换实例解析
- Python随机数用法实例详解【基于random模块】
- [TensorFlow] demo1 tf.random_uniform 函数