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.digraph_generate_random_path

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

Return a random path (or random walk) on a directed graph.

The next node to visit is selected uniformly at random from the outgoing neighbors. If a node of the path has no outgoing neighbor, the path will stop early.

Parameters:
  • graph (PyDiGraph) – 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]