pythonrandom中的随机函数
pythonrandom中的随机函数
Python标准库的random函数可以生成随机浮点数、整数、字符串,也可以随机选择列表序列的要素,打乱数据组等。
1、seed与random函数
seed函数初始化一个随机种子,默认是当前系统时间。
random函数生成一个[0.0,1.0)之间的随机小数。
importrandom
random.seed(10)
x=random.random()
print(x)
2、randint
参数1、参数2必须是整数,函数返回参数1和参数2之间的任意整数。
importrandom
defrand_int(m,n):
delta=n-m
returnround(random.random()*delta+m)
print(rand_int(1,10))
以上就是pythonrandom中随机函数的介绍,希望对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python中s3cmd是什么?
python中s3cmd是什么?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。简单介绍:可以实现使用s3对象存储安装方式:yuminstalls3cmd...详情>>
2023-11-14 19:15:02
python中如何使用pandas实现行数据添加
python中如何使用pandas实现行数据添加python中,pandas是一个数据分析包,可以对数据进行很方便的处理提供了高效地操作大型数据集所需的工具。...详情>>
2023-11-14 16:35:59
python迭代器中Yield方法怎么用?
python迭代器中Yield方法怎么用?Yield用于返回数据,程序执行到yield后,返回结果,记住当前状态,暂停执行,下次调用时,根据上次的状态,返回...详情>>
2023-11-14 16:11:13
python元组拆包如何实现?
python元组拆包如何实现?1、说明把元组一一对应拆出来,就叫做元组拆包。拆包有个要求,元组中的元素数量必须跟接受这些元素的空挡数一致,否则...详情>>
2023-11-14 13:24:22热门推荐
python中any函数如何使用?
沸python operator模块有何用法?
热python中s3cmd是什么?
热python中getattribute方法作用是什么?
新python如何使用TemporaryFile()方法创建临时文件?
python中sys模块是什么?
python的ndarray与pandas的series如何相互转换?
python中如何使用pandas实现行数据添加
python迭代器中Yield方法怎么用?
python中temp是什么意思?
python中Cartopy是什么
python入门:方差和标准差的区别
python切片如何作为占位符使用
python元组拆包如何实现?
技术干货






