random.randint(2, 12) returns same results every time it's run in Python

前端 未结 4 777
小鲜肉
小鲜肉 2020-12-12 01:00

I have a script that generates 10 random numbers between 2 and 12:

repetition = 10
while repetition > 0:
    print(random.randint(2,12))
    repetition =          


        
4条回答
  •  执笔经年
    2020-12-12 01:24

    You can set seed value dependent on the time. Seed value will change with every call.

    import random
    import time
    random.seed(time.clock())
    repetition = 10
    while repetition > 0:
       print(random.randint(2,12))
       repetition = repetition - 1
    

提交回复
热议问题