Note

This is the documentation for the current state of the development branch of rustworkx. The documentation or APIs here can change prior to being released.

rustworkx.graph_generate_random_path

graph_generate_random_path(graph, source, length, seed=None)

Return a random path (or random walk) on an undirected graph.

The next node to visit is selected uniformly at random from the neighbors. If the source node has no neighbor, the random walk stops.

Parameters:
  • graph (PyGraph) – Graph on which the random walk is done.

  • source (int) – Starting node of the path.

  • length (int) – Maximum length of the path.

  • seed (Optional[int]) – seed of the random number generator that chooses the next node.

Returns:

List of visited nodes including the initial node source.

Return type:

list[int]