Details about the random module in python

Source: Internet
Author: User
This article mainly describes the relevant information about the random module of python, which has some reference value. interested friends can refer to the import random

Random. random () # generates a random floating point number between 0 and 1.

Random. randint (start, end) # Generate a random integer in the specified range.

For example, the minimum value of random. randint (1, 10) is 1 and the maximum value is less than or equal to 10.

Random. randrange (start, end) # Generate a random integer in the specified range.

Ramdom. randrange () has a minimum value of 1 and a maximum value of less than 10.

Random. choice randomly returns an element in the sequence.

Random. sample (sequence, which randomly retrieves several elements from the sequence at the same time) is used to specify multiple elements returned from the sequence at the same time.

The difference between choice and choice is that choice can return only one element at a time, and n elements can be returned at the same time in sample.

Random. uniform (start range, end range) is used to retrieve a floating point number within a specified range.

Random. shuffle is used to disrupt the order of elements in a sequence (this function directly modifies the original sequence .)

The above is a detailed description of the random module in python. For more information, see other related articles in the first PHP community!

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.