Function retworkx::undirected_gnp_random_graph[][src]

pub fn undirected_gnp_random_graph(
    py: Python<'_>,
    num_nodes: isize,
    probability: f64,
    seed: Option<u64>
) -> PyResult<PyGraph>

Return a :math:G_{np} random undirected graph, also known as an Erdős-Rényi graph or a binomial graph.

For number of nodes :math:n and probability :math:p, the :math:G_{n,p} graph algorithm creates :math:n nodes, and for all the :math:n (n - 1)/2 possible edges, each edge is created independently with probability :math:p. In general, for any probability :math:p, the expected number of edges returned is :math:m = p n (n - 1)/2. If :math:p = 0 or :math:p = 1, 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 :math:n (n - 1)/2 edges. The run time is :math:O(n + m) where :math:m is the expected number of edges mentioned above. When :math:p = 0, run time always reduces to :math:O(n), as the lower bound. When :math:p = 1, run time always goes to :math:O(n + n (n - 1)/2), as the upper bound. For other probabilities, this algorithm [1]_ runs in :math:O(n + m) time.

For :math:0 < p < 1, the algorithm is based on the implementation of the networkx function fast_gnp_random_graph [2]_

:param int num_nodes: The number of nodes to create in the graph :param float probability: The probability of creating an edge between two nodes :param int seed: An optional seed to use for the random number generator

:return: A PyGraph object :rtype: PyGraph

.. [1] Vladimir Batagelj and Ulrik Brandes, “Efficient generation of large random networks”, Phys. Rev. E, 71, 036113, 2005. .. [2] https://github.com/networkx/networkx/blob/networkx-2.4/networkx/generators/random_graphs.py#L49-L120