The random module in Python

Source: Internet
Author: User
Random.random

Random.random () generates a 0.0~1.0 floating-point number

Random.uniform (word meaning: uniforms, uniforms, uniform, same)

Random.uniform (parameter 1, parameter 2) This function requires a parameter that generates a floating-point number of a specified range. Two parameters one is the lower limit, the other is the upper limit

Random.uniform (1,10) and Random.uniform (10,1) are the same effect (you really like the function of how you love It)

Random.randint

Random.randint (parameter 1, parameter 2) This function requires an argument and generates an integer of the specified range. The first parameter is the lower limit, the second argument is the upper limit

Random.randrange

Random.randrange (parameter 1, parameter 2, Parameter 3 = 1) This function requires a parameter, generates an integer of the specified range, the first parameter is the lower limit, the second argument is the upper limit, the third argument is the same as the range method, and a simple filter can be made (what is the egg used for?). Random even and odd combinations ...)

Random.choice (word meaning: selection)

Random.choice (parameter 1) This function requires a parameter, which randomly gets a value in a string or an ordered list.

Example 1:random.choice ("string") this will pop out a character

Example 2:random.choice (["Oh Da", "I Da", "Meng Meng Da"]) this will pop a value, of course, the yuan can also be thrown into the random

Random.shuffle (word meaning: Shuffle)

Random.shuffle (parameter 1) This function requires a parameter, which randomly disrupts the value in a list, so the argument must be a list

Personal feeling: The function of neuropathy, I hope I can use it in my life

Random.sample (Word meaning: sample, example)

Random.sample (parameter 1, parameter 2) This function requires a parameter, randomly returns the value of a sequence (list, tuple, string), parameter 1 is a sequence, parameter 2 is range

Note: The parameter is a return type and does not change the original sequence value

The random module in Python

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.