def random_k_out_graph(n, k, alpha, self_loops=True, seed=None):
 if (alpha < 0):
  raise ValueError('alpha must be positive')
 random.seed(seed)
 G = nx.empty_graph(n, create_using=nx.MultiDiGraph())
 weights = Counter({v: alpha for v in G})
 for i in range((k * n)):
  u = random.choice([v for (v, d) in G.out_degree() if (d < k)])
  if (not self_loops):
   adjustment = Counter({u: weights[u]})
  else:
   adjustment = Counter()
  v = weighted_choice((weights - adjustment))
  G.add_edge(u, v)
  weights[v] += 1
 G.name = 'random_k_out_graph({0}, {1}, {2})'.format(n, k, alpha)
 return G

def random_k_out_graph ( n , k , alpha , self_loops = True , seed = None ) : if ( alpha < 0 ) : raise ValueError ( 'alpha must be positive' ) random . seed ( seed ) G = nx . empty_graph ( n , create_using = nx . MultiDiGraph ( ) ) weights = Counter ( { v : alpha for v in G } ) for i in range ( ( k * n ) ) : u = random . choice ( [ v for ( v , d ) in G . out_degree ( ) if ( d < k ) ] ) if ( not self_loops ) : adjustment = Counter ( { u : weights [ u ] } ) else : adjustment = Counter ( ) v = weighted_choice ( ( weights - adjustment ) ) G . add_edge ( u , v ) weights [ v ] += 1 G . name = 'random_k_out_graph({0}, {1}, {2})' . format ( n , k , alpha ) return G
returns a random k-out graph with preferential attachment .