美文网首页
乱序和随机抽人程序

乱序和随机抽人程序

作者: 骆旺达 | 来源:发表于2020-09-11 15:08 被阅读0次

    乱序小程序

    import random
    
    group = list(range(0,26))
    print(group)
    random.shuffle(group)
    print(group)
    

    输出
    乱序前:[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
    乱序后:[10, 6, 8, 9, 12, 0, 24, 1, 2, 18, 11, 14, 4, 16, 15, 22, 7, 13, 17, 5, 20, 25, 23, 3, 19, 21]

    随机抽人小程序

    import random
    
    data = []
    # 或者内定data =["员工1","员工2"]
    
    for line in open("file","r"):
         data.append(line)
    
    rs =random.sample(data,6)
    print(rs)
    
    image.png

    相关文章

      网友评论

          本文标题:乱序和随机抽人程序

          本文链接:https://www.haomeiwen.com/subject/apfbektx.html