rustworkx.undirected_gnp_random_graph#
- undirected_gnp_random_graph(num_nodes, probability, /, seed=None)#
Return a
random undirected graph, also known as an Erdős-Rényi graph or a binomial graph.For number of nodes
and probability , the graph algorithm creates nodes, and for all the possible edges, each edge is created independently with probability . In general, for any probability , the expected number of edges returned is . If or , the returned graph is not random and will always be an empty or a complete graph respectively. An empty graph has zero edges and a complete undirected graph has edges. The run time is where is the expected number of edges mentioned above. When , run time always reduces to , as the lower bound. When , run time always goes to , as the upper bound. For other probabilities, this algorithm [1] runs in time.For
, the algorithm is based on the implementation of the networkx functionfast_gnp_random_graph
[2]- Parameters:
num_nodes (int) – The number of nodes to create in the graph
probability (float) – The probability of creating an edge between two nodes
seed (int) – An optional seed to use for the random number generator
- Returns:
A PyGraph object
- Return type: