| 108 | @patch_docstring(nxa.gnp_random_graph) |
| 109 | @py_random_state(2) |
| 110 | def gnp_random_graph(n, p, seed=None, directed=False): |
| 111 | if directed: |
| 112 | edges = itertools.permutations(range(n), 2) |
| 113 | G = nx.DiGraph() |
| 114 | else: |
| 115 | edges = itertools.combinations(range(n), 2) |
| 116 | G = nx.Graph() |
| 117 | G.add_nodes_from(range(n)) |
| 118 | if p <= 0: |
| 119 | return G |
| 120 | if p >= 1: |
| 121 | return complete_graph(n, create_using=G) |
| 122 | |
| 123 | for e in edges: |
| 124 | if seed.random() < p: |
| 125 | G.add_edge(*e) |
| 126 | return G |
| 127 | |
| 128 | |
| 129 | # add some aliases to common names |