def random_uniform_k_out_graph(n, k, self_loops=True, with_replacement=True, seed=None):
 random.seed(seed)
 if with_replacement:
  create_using = nx.MultiDiGraph()
  def sample(v, nodes):
   if (not self_loops):
    nodes = (nodes - {v})
   return (random.choice(list(nodes)) for i in range(k))
 else:
  create_using = nx.DiGraph()
  def sample(v, nodes):
   if (not self_loops):
    nodes = (nodes - {v})
   return random.sample(nodes, k)
 G = nx.empty_graph(n, create_using=create_using)
 nodes = set(G)
 for u in G:
  G.add_edges_from(((u, v) for v in sample(u, nodes)))
 G.name = 'random_uniform_k_out_graph({}, {})'.format(n, k)
 return G

def random_uniform_k_out_graph ( n , k , self_loops = True , with_replacement = True , seed = None ) : random . seed ( seed ) if with_replacement : create_using = nx . MultiDiGraph ( ) def sample ( v , nodes ) : if ( not self_loops ) : nodes = ( nodes - { v } ) return ( random . choice ( list ( nodes ) ) for i in range ( k ) ) else : create_using = nx . DiGraph ( ) def sample ( v , nodes ) : if ( not self_loops ) : nodes = ( nodes - { v } ) return random . sample ( nodes , k ) G = nx . empty_graph ( n , create_using = create_using ) nodes = set ( G ) for u in G : G . add_edges_from ( ( ( u , v ) for v in sample ( u , nodes ) ) ) G . name = 'random_uniform_k_out_graph({}, {})' . format ( n , k ) return G
returns a random k-out graph with uniform attachment .