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)

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • 相关阅读:
    RN-Android构建失败:Caused by: org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'AwesomeProject'.
    Android更新包下载成功后不出现安装界面
    真机调试: The application could not be installed: INSTALL_FAILED_TEST_ONLY
    react native 屏幕尺寸转换
    Android Studio生成签名文件,自动签名,以及获取SHA1和MD5值
    React Native安卓真机调试
    git提交代码报错Permission denied, please try again
    The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
    命令行设置快捷命令
    Linux 常用指令
  • 原文地址:https://www.cnblogs.com/lovepy3/p/8748530.html
Copyright © 2011-2022 走看看