random_walk#

random_walk(G, *, start, weight=None, seed=None)[source]#

Yields nodes visited by a random walk starting at start.

The generator yields nodes in walk order, including start as the first yielded node, and terminates when there is no valid outgoing transition.

If weight is None, transitions are uniform over neighbors. If weight is a string, transitions are proportional to that edge attribute, defaulting to 1 if missing.

Parameters:
GNetworkX graph

The input graph.

startnode

Starting node for the random walk.

weightstring or None, optional (default=None)

Edge attribute name to interpret as the transition weight. If None, each edge has weight 1.

seedinteger, random_state, or None (default=None)

Indicator of random number generation state. See Randomness.

Returns:
iterator

An iterator yielding visited nodes in walk order.