Generate random integers between 0 and 9

前端 未结 19 1733
无人共我
无人共我 2020-11-22 15:37

How can I generate random integers between 0 and 9 (inclusive) in Python?

For example, 0, 1, 2, 3, 4

19条回答
  •  無奈伤痛
    2020-11-22 16:26

    Try:

    from random import randrange
    print(randrange(10))
    

    Docs: https://docs.python.org/3/library/random.html#random.randrange

提交回复
热议问题