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
Output
The code is as follows:
0.787074152336 95 1 [4, 5, 2, 3, 1]
[Related recommendations]
2. Example tutorial of Python random() function
3. Share the random module in Python to generate random Number example tutorial
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!