python-Random Module-random

Source: Internet
Author: User

Random

Generate Random variables

Generates a random number of [0, 1) . Random

Import Randomrandom_number = Random.random () print (random_number) print (Random_number + 1)

Generates a [start, end] random number . Uniform

Import randomrandom_number = Random.uniform (0, ten) print (Random_number)

Generates a [start, end] interval random integer . Randint

Import Randomrandom_number = Random.randint (1, ten) print (Random_number)

Generate (start, end) interval random integer randrange

Import Randomrandom_number = Random.randrange (1, ten) print (Random_number)

Randomly take a value from a sequence choice

Import randomrandom_sequence = Random.choice (["1", "2", "3"]) print (random_sequence)

Sampling sample randomly from a sequence

Import randomtarget_str = "0123456789abcdefghijklmnopqrstuvwxyz" random_sequence = Random.sample (target_str, 6) print ( Random_sequence) # 6-digit random verification code print (". Join (Random_sequence))

Arithmetic Operation Verification Code implementation

Import randomnumber_str = "123456789" letter_str = ' abcdefghijklmnopqrstuvwxyz ' operator = "+-x" RANDOM_STR = Random.choice (NUMBER_STR) + random.choice (operator) +              Random.choice (number_str) + random.choice (operator) +              Random.choice (number_str) print (Random_str.replace (' x ', ' * ')) print (eval (random_str.replace (' x ', ' * ')))

python-Random Module-random

Related Article

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.