Decorator to generate a random.Random instance (or equiv).

The decorator processes the argument indicated by random_state_argument using nx.utils.create_py_random_state(). The argument value can be a seed (integer), or a random number generator:

If int, return a random.Random instance set with seed=int.
If random.Random instance, return it.
If None or the `random` package, return the global random number
generator used by `random`.
If np.random package, return the global numpy random number
generator wrapped in a PythonRandomInterface class.
If np.random.RandomState instance, return it wrapped in
If a PythonRandomInterface instance, return it
random_state_argumentstring or int

The name of the argument or the index of the argument in args that is to be converted to the random.Random instance or numpy.random.RandomState instance that mimics basic methods of random.Random.


Function whose random_state_argument is converted to a Random instance.

See also



Decorate functions like this:

def random_float(random_state=None):
    return random_state.rand()

def random_float(rng=None):
    return rng.rand()

def random_array(dims, seed=12345):
    return seed.rand(*dims)