/images/github_pfp.png

152334H

Multiprocessing and random()

Let’s say, for some odd reason, you’re hosting a Python service that:

  1. takes requests that run large computations based on a randomly generated number (a “seed”)
  2. spreads work across multiple workers to handle many requests

Then, it’s likely you’ll introduce a subtle randomness bug that leads to duplicate seeds appearing. Let me explain: