生成0到9之间的随机整数

我如何在Python中生成0到9(含)之间的随机整数?

0123456789


尝试:

from random import randint
print(randint(0, 9))

更多信息:https://docs.python.org/3/library/random.html#random.randint


import random
print(random.randint(0,9))

random.randint(a, b)

返回一个随机整数N,使得a <= N <= b。

文档:https://docs.python.org/3.1/library/random.html#random.randint


尝试这个:

from random import randrange, uniform

# randrange gives you an integral value
irand = randrange(0, 10)

# uniform gives you a floating-point value
frand = uniform(0, 10)
链接地址: http://www.djcxy.com/p/2923.html

上一篇: Generate random integers between 0 and 9

下一篇: How do I generate a random int number in C#?