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
startas the first yielded node, and terminates when there is no valid outgoing transition.If
weightis None, transitions are uniform over neighbors. Ifweightis 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.