发布时间:2023-11-13 17:00
r.random()
min,max可以为小数
r.uniform(10.78, 12.5)
r.randint(12, 56)
(r.choice(tuple1)
print(r.randrange(0, 60, 3))
print(r.sample(names, 2))
r.shuffle(names)
以上变换中,字典类型均不可以!
import random as r
names = [\'国成\', \'翼飞\', \'柱鼎\', \'宝明\', \'清源\', \'超\', \'战国\', \'政辉\',
\'贤\', \'紫洋\', \'轶康\', \'泳\', \'博通\', \'显伯\', \'嘉毓\', \'思琴\', \'锶溢\']
tuple1 = (1, 2, 3, 4, 5)
dict1 = {
\"math\": 578,
\'english\': 980,
\"chinese\": 789,
\"message\": \"这是一则非常重要的消息\",
\"password\": \"请记好你的密码!\"
}
print(r.random(), r.uniform(10.78, 12.5), r.randint(12, 56))
print(r.choice(tuple1), r.choice(range(0, 5)), r.choice(names))
print(r.randrange(0, 60, 3))
print(r.sample(names, 2))
r.shuffle(names)
print(names)