def random_powerlaw_tree_sequence(n, gamma=3, seed=None, tries=100):
 if (seed is not None):
  random.seed(seed)
 z = nx.utils.powerlaw_sequence(n, exponent=gamma)
 zseq = [min(n, max(int(round(s)), 0)) for s in z]
 z = nx.utils.powerlaw_sequence(tries, exponent=gamma)
 swap = [min(n, max(int(round(s)), 0)) for s in z]
 for deg in swap:
  if (((2 * n) - sum(zseq)) == 2):
   return zseq
  index = random.randint(0, (n - 1))
  zseq[index] = swap.pop()
 raise nx.NetworkXError(('Exceeded max (%d) attempts for a valid tree sequence.' % tries))

def random_powerlaw_tree_sequence ( n , gamma = 3 , seed = None , tries = 100 ) : if ( seed is not None ) : random . seed ( seed ) z = nx . utils . powerlaw_sequence ( n , exponent = gamma ) zseq = [ min ( n , max ( int ( round ( s ) ) , 0 ) ) for s in z ] z = nx . utils . powerlaw_sequence ( tries , exponent = gamma ) swap = [ min ( n , max ( int ( round ( s ) ) , 0 ) ) for s in z ] for deg in swap : if ( ( ( 2 * n ) - sum ( zseq ) ) == 2 ) : return zseq index = random . randint ( 0 , ( n - 1 ) ) zseq [ index ] = swap . pop ( ) raise nx . NetworkXError ( ( 'Exceeded max (%d) attempts for a valid tree sequence.' % tries ) )
returns a degree sequence for a tree with a power law distribution .