Share an example tutorial on random (randomly generated numbers) in Python

零下一度
Release: 2017-05-20 14:55:29
Original
2257 people have browsed it

This article mainly introduces Pythonrandomly generated number module random usage examples. This article directly gives sample code. Friends in need can refer to it

The code is as follows:

#!/usr/bin/env python#coding=utf-8import random
#生成[0, 1)直接随机浮点数print random.random()
#[x, y]中的随机整数print random.randint(1, 100)
list = [1, 2, 3, 4, 5]#随机选取print random.choice(list)
#随机打乱random.shuffle(list)print list
Copy after login

Output

The code is as follows:

0.787074152336
95
1
[4, 5, 2, 3, 1]
Copy after login

[Related recommendations]

1. Detailed explanation of mathematics and random numbers in the Python standard library (math package, random package)

2. Example tutorial of Python random() function

3. Share the random module in Python to generate random Number example tutorial

4. Share an example of how Python random generates N random numbers that do not repeat in a certain interval

5. Python Common methods and usage examples of random module (obtaining random numbers)

6. Common methods of Python random module

7. Python module learning: random Random number generation

The above is the detailed content of Share an example tutorial on random (randomly generated numbers) in Python. 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