Skip to main content

sample_edges

Function sample_edges 

Source
pub fn sample_edges(
    graph: &Graph,
    count: usize,
    seed: u64,
) -> IgraphResult<Vec<(VertexId, VertexId)>>
Expand description

Uniformly sample count edges from the graph without replacement.

Returns a random subset of the graph’s edges. If count exceeds the number of edges, all edges are returned (shuffled).

§Parameters

  • graph — The input graph.
  • count — Number of edges to sample.
  • seed — PRNG seed for deterministic sampling.

§Examples

use rust_igraph::{Graph, sample_edges};

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,3),(3,4),(4,0)], false, Some(5)
).unwrap();

let sampled = sample_edges(&g, 3, 42).unwrap();
assert_eq!(sampled.len(), 3);
for &(u, v) in &sampled {
    assert!(g.has_edge(u, v));
}