Make random number using code more robust
Psudorandom numbers are used in several places in Kwant. In order to improve general robustness (reproducibility, flexibility), we should follow the following rules:
-
Code that performs computations using random numbers (e.g.
kwant.rmt
) should have a way configure the generator to be used. The common approach in the scientific python world is to have arandom_state
parameter that can be eitherNone
(-> use numpy's default RNG instance, i.e.np.random.mtrand._rand
), or an integer (-> use this as a seed for a new RNG instance), or an instance ofnp.random.RandomState
(use this). We probably shouldn't check for this specific type, but rather rely on duck typing. -
Code that uses random numbers internally as an implementation detail (e.g.
kwant.plotter
) should use a private RNG. If instantiating the numpy's or python's Mersenne twister RNG takes too much time, we can probably use a simpler generator. -
Tests that use random numbers should use private RNG instances with fixed seeds for reproducibility and independence from the order in which tests are executed.