#

Note

This documents the development version of NetworkX. Documentation for the current release can be found here.

#

networkx.utils.decorators.preserve_random_state

preserve_random_state(func)[source]

Decorator to preserve the numpy.random state during a function.

Parameters

func (function) – function around which to preserve the random state.

Returns

wrapper – Function which wraps the input function by saving the state before calling the function and restoring the function afterward.

Return type

function

Examples

Decorate functions like this:

@preserve_random_state
def do_random_stuff(x, y):
    return x + y * numpy.random.random()

Notes

If numpy.random is not importable, the state is not saved or restored.