zoukankan      html  css  js  c++  java
  • python之random模块

    from random import *
    
    random1 = random()
    print(type(random1), random1)  # [0, 1)
    randint1 = randint(2, 100)  # [2,100]
    print(type(randint1), randint1)
    result = [3, 45, 2, 1, -8]
    sample1 = sample(result, 2)
    print(type(sample1), sample1)
    rr = randrange(2, 10, 2)  # 结果为2 4 6 8 中的其中一个
    print(type(rr), rr)
    
    
    def v_code(char_count):
        chs = list(range(48, 58)) + list(range(65, 91)) + list(range(97, 123))
        result = ''
        for i in range(char_count):
            result += chr(choice(chs))
        return result
    
    
    print(v_code(5))

    输出:(结果是随机的,下面只是一次运行的结果,仅做参考)

    <class 'float'> 0.6281382442051219 
    <class 'int'> 64
    <class 'list'> [45, 2]
    <class 'int'> 2
    AZwq9

  • 相关阅读:
    Muddy Fields
    LightOJ 1321
    LightOJ 1085
    LightOJ 1278
    LightOJ 1341
    LightOJ 1340
    vijos 1426 背包+hash
    vijos 1071 01背包+输出路径
    vijos 1907 DP+滚动数组
    vijos 1037 背包+标记
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7569308.html
Copyright © 2011-2022 走看看