In Python, what is the best way to generate some random number using a certain seed but without reseeding the global state? In Java, you could write simply:
Random r = new Random(seed);
r.nextDouble();
and the standard Math.random()
would not be affected. In Python, the best solution that I can see is:
old_state = random.getstate()
random.seed(seed)
random.random()
random.setstate(old_state)
Is this idiomatic Python? It seems much less clean than the Java solution that doesn't require "restoring" an old seed. I'd love to know if there's a better way to do this.