DEV Community

Discussion on: How to fix an Endless Loop in Python?

Collapse
 
codemouse92 profile image
Jason C. McDonald

Regarding the random numbers, you need to seed random with a changing number. Not seeding, or always seeding with the same number, will result in the same random numbers being produced.

So, the most common way around this is to use the current time to seed random.

import random
from datetime import datetime
random.seed(datetime.now())

(Disclaimer: While this is what I've used for years in Python, I double-checked the exact syntax like I always do. This version comes from this StackOverflow answer)

Collapse
 
crhodes2 profile image
crhodes

It also worked out. Thank you!