zoukankan      html  css  js  c++  java
  • python随机数,随机选择……random

    import random
    from random import random, uniform, randint, randrange, choice, sample, shuffle
    
    list = ['jack', 'rose', 'tom', 'jerry']
    print(random())  # 随机小数 0.0 <= x < 1.0
    print(uniform(1, 10))  # 随机小数 x, 1.0 <= x < 10.0
    print(randint(1, 10))  # 随机整数 1 to 10, endpoints included
    print(randrange(0, 101, 2))  # 随机0-101,步进2,也就是偶数
    print(randrange(0, 101, 5))  # 随机0-101,步进5,也就是5的倍数
    print(choice('abcdefghij'))  # 随机字符串中的一个字符
    items = [1, 2, 3, 4, 5, 6, 7]
    print(items)
    shuffle(items)  # 重新随机排序
    print(items)
    print(sample([1, 2, 3, 4, 5], 3))  # 随机选3个
    

      

  • 相关阅读:
    I
    H
    G
    F
    E
    论js里面的for循环
    js常见问题之为什么点击弹出的i总是最后一个
    array类型的方法
    string类型的方法
    for in在对象和数组中的应用
  • 原文地址:https://www.cnblogs.com/jackadam/p/7845883.html
Copyright © 2011-2022 走看看