Python randomly generates number modules random using instances
- 2020-05-09 18:45:08
- OfStack
code
#!/usr/bin/env python
#coding=utf-8
import random
# generate [0, 1) Directly random floating point number
print random.random()
#[x, y] Random integer in
print random.randint(1, 100)
list = [1, 2, 3, 4, 5]
# Randomly selected
print random.choice(list)
# Random disturb
random.shuffle(list)
print list
The output
0.787074152336
95
1
[4, 5, 2, 3, 1]