Context
Say, we want to use the Box-Muller algorithm. Starting from a couple of random numbers U1 and U2, we can generate G1 and G2. Now, for any call, we just want to output either G1 or G2. In other languages, we could use static variables to be able to know if we need to generate a new couple. How can it be done in Python?
First thoughts
I know, much had been said about static variables in Python, I also must say I'm a bit confused as the answers are quite scattered. I found this thread and references therein. By that thread, the solution here would be to use a generator.
The devil's in the details
Now, the problem is, how do we initialize the generator and how do we retain, say G2, for the next yield
?