title: Generate a scale-free network with a power-law degree distributions
body: <p>I'm trying to generate couples of scale-free networks having:</p>
  
  <ul>
  <li>degree distributions following power laws with the same exponent</li>
  <li>the exact same number of nodes.</li>
  </ul>
  
  <p>I need to build at least 60 of those couples and run a simulation for each.</p>
  
  <p>In order to do this, I need a way to generate a network of exactly n nodes with the above properties.</p>
  
  <p>Right now, I'm able to generate a graph with a degree distribution following a power laws with a given exponent, using the NetworkX Python library, with this code</p>
  
  <pre><code>import networkx as nx
  import matplotlib.pyplot as plt
  
  #create a graph with degrees following a power law distribution
  s = nx.utils.powerlaw_sequence(100, 2.5) #100 nodes, power-law exponent 2.5
  G = nx.expected_degree_graph(s, selfloops=False)
  
  print(G.nodes())
  print(G.edges())
  
  #draw and show graph
  pos = nx.spring_layout(G)
  nx.draw_networkx(G, pos)
  plt.show()
  </code></pre>
  
  <p>However, this generates a graph with many isolated nodes, and usually more than a single connected component.</p>
  
  <p>I can throw away the isolated nodes, but then my final network will have less nodes than I intended, and it may not be a single network. It may be 2 or more separate connected components.</p>