随机数

 

import random
for i in range(10):
    x = random.random()
    print(x)

The function randint takes parameters low and high and returns an integer between low and high (including both).
>>> random.randint(5, 10)
5
>>> random.randint(5, 10)
9
To choose an element from a sequence at random, you can use choice:
>>> t = [1, 2, 3]
>>> random.choice(t)
2
>>> random.choice(t)
3

 

 

posted @ 2018-12-18 11:38  anobscureretreat  阅读(204)  评论(0)    收藏  举报