Skip to content

Commit

Permalink
Avoid self loops in directed version of fast_gnp
Browse files Browse the repository at this point in the history
  • Loading branch information
hagberg committed Jun 26, 2011
1 parent 71b9795 commit f4904ef
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion networkx/generators/random_graphs.py
Expand Up @@ -96,10 +96,15 @@ def fast_gnp_random_graph(n, p, seed=None, directed=False):
while v < n:
lr = math.log(1.0 - random.random())
w = w + 1 + int(lr/lp)
while w>= n and v < n:
if v == w: # avoid self loops
w = w + 1
while w >= n and v < n:
w = w - n
v = v + 1
if v == w: # avoid self loops
w = w + 1
if v < n:
if v == w:
G.add_edge(v, w)
else:
while v < n:
Expand Down

0 comments on commit f4904ef

Please sign in to comment.