Python Basic Learning random number module

Source: Internet
Author: User

Random number Module

Import Random

Random.random () between #随机一个浮点小数 0-1
Random.uniform (1,3) #指定随机的小小数范围
Random.randint (1,10) #随机一个整数 (parameter is random range)
Random.randrange () #随机对一个range范围进行随机
Random.choice () #随机一个序列 (can be strings and lists, etc.)
Random.sample (str,2) #从一个序列或字符串中选取特定数量的值
Random.shuffle () #洗牌, disrupting a sequence

Time-Random Verification code

Yzm = ' '
For AAA in range (4):
BBB = Random.randrange (4)
If AAA = = BBB:
TMP = Chr (Random.randint (65,90)) #先从数字65-90 random, then converted to Assci code (assic 65-90 in uppercase English letters)
Else
TMP = STR (random.randint (0,9))
Yzm + = tmp
Print (YZM)

Python Basic Learning random number module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.