pub fn random_gnp_graph<R: Rng + ?Sized, Ty: EdgeType, Ix: IndexType>(
    rng: &mut R,
    n: usize,
    p: f64
) -> Graph<(), (), Ty, Ix>
Expand description

Generates a random graph according to the G(n,p) Erdős-Rényi model. The resulting graph has n nodes and edges are selected with probability p from the set of all possible edges (excluding loop edges).

Examples

use petgraph_gen::random_gnp_graph;
use petgraph::graph::{DiGraph, UnGraph};
use rand::SeedableRng;

let mut rng = rand::rngs::SmallRng::seed_from_u64(42);
let undirected_graph: UnGraph<(), ()> = random_gnp_graph(&mut rng, 10, 0.3);
assert_eq!(undirected_graph.node_count(), 10);
assert_eq!(undirected_graph.edge_count(), 15); // out of 45 possible edges

let directed_graph: DiGraph<(), ()> = random_gnp_graph(&mut rng, 10, 0.5);
assert_eq!(directed_graph.node_count(), 10);
assert_eq!(directed_graph.edge_count(), 40); // out of 90 possible edges