Random Number Module

Source: Internet
Author: User
Import random # print (random. random () #0-1 does not include 1 random floating point print (random. randint () #1-10 contains the print (random. randrange () #1-10 contains 1 and does not include 10 integers print (random. sample (["AAA", ["A", "B"], 3, 4, 5], 2 )) # specify a range and specify the required random number. ls = ["1", "2", "3", "4"] Random. shuffle (LS) # print (LS) print (random. choice ([1, 2, 3]) # randomly select a print (random. choices ([1, 2, 3, 4, 5, 6, 7], K = 2) # random selection of the specified number # Random verification code length custom including 0-9 A-Z A-zdef get_auth_code (length): res = "" For I in range (length): A = random. randint (0, 9) B = CHR (random. randint (65,90) c = CHR (random. randint (97,122) S = random. choice ([a, B, c]) RES + = STR (s) return resprint (get_auth_code (4) # result: 4 random values of [0-9 A-Z A-Z] print (random. uniform (1, 3) # returns a floating point number between A and B. If A> B, it is the floating point number between B and. Both A and B may appear in the result.

 

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.