networkx.utils.decorators.preserve_random_state¶
- preserve_random_state(func)[source]¶
Decorator to preserve the numpy.random state during a function.
Deprecated since version 2.6: This is deprecated and will be removed in NetworkX v3.0.
- Parameters
- funcfunction
function around which to preserve the random state.
- Returns
- wrapperfunction
Function which wraps the input function by saving the state before calling the function and restoring the function afterward.
Notes
If numpy.random is not importable, the state is not saved or restored.
Examples
Decorate functions like this:
@preserve_random_state def do_random_stuff(x, y): return x + y * numpy.random.random()