zoukankan      html  css  js  c++  java
  • Day 4-2 random模块

    1 import random
    2 random.randint(1,100)  # 从1到100中随机取出一个数.包含100
    3 random.randrange(1,100) #功能和上面一样.只是不包含100.
    4 random.random()         # 取一个随机浮点数.
    5 random.choice("123kldsjfoiauofjdlkcvjhasfhsafjr")  # 从字符串中随机返回一个字符
    6 random.sample("vajoure034zmvm2i0989383242u",4)  # 返回指定数量的字符串

    生成一个随机验证码:

    1 # 生成一个随机验证码,需要string模块
    2 import string
    3 string.ascii_letters  # 大小写字母
    4 string.digits        # 数字.
    5 string.punctuation   # 特殊字符
    6 s = string.ascii_letters + string.digits
    7 s1 = ''.join(random.sample(s,4))   # 生成一个4位的随机验证码.
    8 print(s1)

       打乱顺序:

    1 # 打乱顺序
    2 li = list(range(100))  # 生成一个列表
    3 random.shuffle(li)    #打乱列表中的顺序
    4 print(li)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • 相关阅读:
    Inline Hook 钩子编写技巧
    FPS 游戏实现D3D透视 (API Hook)
    FPS 游戏实现GDI透视 (三角函数)
    X86驱动:恢复SSDT内核钩子
    X86驱动:挂接SSDT内核钩子
    VS2013+WDK8.1 驱动开发环境配置
    C/C++ 语言之反汇编揭秘:目录
    WinRAR 去广告的姿势
    C/C++ 实现反调试的手段
    springboot项目部署到独立tomcat的爬坑集锦
  • 原文地址:https://www.cnblogs.com/lovepy3/p/8748530.html
Copyright © 2011-2022 走看看