Warning

This documents an unmaintained version of NetworkX. Please upgrade to a maintained version and see the current NetworkX documentation.

networkx.utils.decorators.random_state

random_state(random_state_index)[source]

Decorator to generate a numpy.random.RandomState instance.

Argument position random_state_index is processed by create_random_state. The result is a numpy.random.RandomState instance.

Parameters

random_state_index (int) – Location of the random_state argument in args that is to be used to generate the numpy.random.RandomState instance. Even if the argument is a named positional argument (with a default value), you must specify its index as a positional argument.

Returns

_random_state – Function whose random_state keyword argument is a RandomState instance.

Return type

function

Examples

Decorate functions like this:

@np_random_state(0)
def random_float(random_state=None):
    return random_state.rand()

@np_random_state(1)
def random_array(dims, random_state=1):
    return random_state.rand(*dims)

See also

py_random_state()