Skip to main content

random_walk

Function random_walk 

Source
pub fn random_walk(
    adjacency: &[Vec<usize>],
    start_node: usize,
    walk_length: usize,
    rng_seed: u64,
) -> Result<Vec<usize>>
Expand description

Perform a uniform random walk on an unweighted graph.

Starting from start_node, at each step a uniformly random neighbour is chosen. If the current node has no neighbours the walk terminates early.

§Parameters

  • adjacency – adjacency list (unweighted); adjacency[u] contains the neighbours of node u.
  • start_node – index of the walk’s first node.
  • walk_length – desired total number of nodes in the walk (including the starting node).
  • rng_seed – seed for the internal pseudo-random number generator.

§Returns

A Vec<usize> of length ≤ walk_length with the visited node sequence.

§Errors

Returns GraphError::InvalidParameter if start_node is out of range.