python--Random Number Module

Source: Internet
Author: User

Import RandomImport StringPrint (Random.randint (1, 199)) # [1,199] randomly take an integer s = Random.choice ([' qwe ', ' wer ', ' ert ') # Randomly take an element Print (s) print (string.digits)# All the numbers 0-9Print (String.ascii_lowercase)# all lowercase lettersPrint (String.ascii_uppercase)# all uppercase lettersPrint (string.ascii_letters)# All lowercase letters + all uppercase lettersPrint (string.punctuation)# All the special charactersres = Random.sample (string.digits,3) # randomly fetch n elements Print (res) print (". Join (RES))res = Random.uniform (1, 9) # take random decimals Print (RES) print (round (res),2) # Keep Several decimal places, if after rounding, the last decimal number is 0 does not show the last Print (Random.random ())# Take a random decimal between 0-1s = [' A ', ' B ', ' C ', ' d ', ' e '] Random.shuffle (s)# random Shuffle orderPrint (s)

python--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.