Python_面向对象_random模块

#--random 随机模块
#random() 获取随机0-1之间的小数
#randrange() 随机获取指定范围内的整数(包含开始值,不包含结束值,间隔值)
#uniform() 获取指定范围内的随机小数(包含开始值,不包含结束值)
#choice() 随机获取序列中的值
#shuffle() 随机打乱序列中的值(直接打乱原序列)

==============================================================================

import random
res = random.random()
print(res)

#randrange() 随机获取指定范围内的整数(包含开始值,不包含结束值,间隔值)
res = random.randrange(1,10)
print(res)

res = random.randrange(1,10,2)
print(res)

#uniform() 获取指定范围内的随机小数(包含开始值,不包含结束值)
res = random.uniform(1,10)
print(res)

#choice() 随机获取序列中的值
listvar = [1,2,3,4,5,6]
res = random.choice(listvar)
print(res)

#shuffle() 随机打乱序列中的值(直接打乱原序列)
res = random.shuffle(listvar)
print("<123>")
print(res)
print(listvar)

猜你喜欢

转载自www.cnblogs.com/bling-bling-star/p/9398097.html