python 中 random模块的用法

 1 import random
 2 
 3 print( random.randint(1,10) )        # 产生 1 到 10 的一个整数型随机数  
 4 print( random.random() )             # 产生 0 到 1 之间的随机浮点数
 5 print( random.uniform(1.1,5.4) )     # 产生  1.1 到 5.4 之间的随机浮点数,区间可以不是整数
 6 print( random.choice('tomorrow') )   # 从序列中随机选取一个元素
 7 print( random.randrange(1,100,2) )   # 生成从1到100的间隔为2的随机整数
 8 
 9 a=[1,3,5,6,7]                # 将序列a中的元素顺序打乱
10 random.shuffle(a)
11 print(a)
12 ————————————————

版权声明:本文为CSDN博主「Karl_Blog」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/larykaiy/article/details/83118538

猜你喜欢

转载自www.cnblogs.com/XiaoF0725/p/11451389.html