Generate random integers between 0 and 9

前端 未结 19 1535
无人共我
无人共我 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:30

    Try this:

    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)
    
    0 讨论(0)
提交回复
热议问题