Detailed explanation of python's random module

高洛峰
Release: 2017-03-26 17:53:42
Original
1224 people have browsed it

import random

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

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

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

random.randrange(start, end) #Generate within the specified range of random integers.

ramdom.randrange(1,10) The minimum is 1 and the maximum is less than 10

random.choice(sequence) Randomly returns an element in the sequence.

random.sample (sequence, randomly take several elements from the sequence at the same time) is used to specify to return multiple elements from this sequence at the same time. The difference between

and choice is that choice can only return one element randomly, while sample can return n elements at the same time.

random.uniform (start range, end range) is used to get a floating point number in a specified range.

random.shuffle(sequence) is used to disrupt the order of elements in a sequence (this function will directly modify the original sequence.)

The above is the detailed content of Detailed explanation of python's random module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!