Lesson 031 —— random 模块

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/woodhost/article/details/84876269

Lesson 031 —— random 模块

关于 random 模块的一些方法介绍。

  1. random.random(): 返回一个 (0, 1) 的浮点型随机数
  2. random.randint(a, b): 返回一个 [a, b] 的整型随机数
  3. random.randrange(a, b): 返回一个 [a, b) 的整型随机数
  4. random.choice(iter): 随机选择其中的一个值,iter 是可迭代对象,可以是列表、元组、字符串、集合等。
  5. random.sample(iter[, n]): 与 choice ;类似,随机选择其中 n 个值。
  6. random.uniform(a, b): 随机选择 (a, b) 范围的浮点型随机数。
  7. random.shuffle(item): 将 item 中的数据随机排列(即打乱)。

猜你喜欢

转载自blog.csdn.net/woodhost/article/details/84876269
今日推荐