python-Module-random

Source: Internet
Author: User

There are many places in the program that require random characters, such as random verification codes for login sites, and random strings can easily be generated in Python via the random module.

Example: Lotto, company annual draw

>>> Import random>>> random.randint (1,100)  #1 100 takes a random number in the middle, including 10032>>> Random.randint (1,100) 59>>> random.randint (1,100) 32>>>random.randrange (1-100)  #1 100 in the middle takes a random number, does not contain 10022 >>>random.choice (' da124#! ')  #从字符串里返回随机的东西, the spell random verification code may be used to ' 4 ' >>>random.sample (' da124#! ', 3)   #返回3个随机值 [' # ', ' 4 ', ' 1 ']>>> import string>>> string.digits ' 0123456789 ' >>> string.ascii_letters ' Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz ' >>> string.hexdigits ' 0123456789abcdefABCDEF '

  

python-Module-random

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.