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.

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:

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

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