Skip to content

Comment on Ask HN: How many times will this loop run on average?

Comments

You’re calculating a random number every time the loop runs. If you want an average of 50 you should call random outside the loop and save the value to be compared each time.

Yes, that's true. I don't want an average of 50. My initial guess of 50 is wrong. I am trying to understand why the average turned out to be approximately 12.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.