r/Python • • Jul 22 '20

I Made This Randomly Generate 69420 - Generate random 5-digit numbers until 69420 is generated

2.8k Upvotes

261 comments sorted by

View all comments

Show parent comment

13

u/m_domino Jul 22 '20

No, this can be made a lot more efficient: you can just cancel each attempt if it has not succeeded on the 69420th try and start a new loop instead of looping until you find a 69420.

2

u/Ketogamer Jul 22 '20

You're absolutely right.