code: def random_k_out_graph(n, k, alpha, self_loops=True, seed=None):
      """Returns a random `k`-out graph with preferential attachment.
  
      A random `k`-out graph with preferential attachment is a
      multidigraph generated by the following algorithm.
  
      1. Begin with an empty digraph, and initially set each node to have
         weight `alpha`.
      2. Choose a node `u` with out-degree less than `k` uniformly at
         random.
      3. Choose a node `v` from with probability proportional to its
         weight.
      4. Add a directed edge from `u` to `v`, and increase the weight
         of `v` by one.
      5. If each node has out-degree `k`, halt, otherwise repeat from
         step 2.
  
      For more information on this model of random graph, see [1].
  
      Parameters
      ----------
      n : int
          The number of nodes in the returned graph.
  
      k : int
          The out-degree of each node in the returned graph.
  
      alpha : float
          A positive :class:`float` representing the initial weight of
          each vertex. A higher number means that in step 3 above, nodes
          will be chosen more like a true uniformly random sample, and a
          lower number means that nodes are more likely to be chosen as
          their in-degree increases. If this parameter is not positive, a
          :exc:`ValueError` is raised.
  
      self_loops : bool
          If True, self-loops are allowed when generating the graph.
  
      seed : integer, random_state, or None (default)
          Indicator of random number generation state.
          See :ref:`Randomness<randomness>`.
  
      Returns
      -------
      :class:`~networkx.classes.MultiDiGraph`
          A `k`-out-regular multidigraph generated according to the above
          algorithm.
  
      Raises
      ------
      ValueError
          If `alpha` is not positive.
  
      Notes
      -----
      The returned multidigraph may not be strongly connected, or even
      weakly connected.
  
      References
      ----------
      [1]: Peterson, Nicholas R., and Boris Pittel.
           "Distance between two random `k`-out digraphs, with and without
           preferential attachment."
           arXiv preprint arXiv:1311.5961 (2013).
           <https://arxiv.org/abs/1311.5961>
  
      """
      if alpha < 0:
          raise ValueError("alpha must be positive")
      G = nx.empty_graph(n, create_using=nx.MultiDiGraph)
      weights = Counter({v: alpha for v in G})
      for i in range(k * n):
          u = seed.choice([v for v, d in G.out_degree() if d < k])
          # If self-loops are not allowed, make the source node `u` have
          # weight zero.
          if not self_loops:
              adjustment = Counter({u: weights[u]})
          else:
              adjustment = Counter()
          v = weighted_choice(weights - adjustment, seed=seed)
          G.add_edge(u, v)
          weights[v] += 1
      return G
  
file_path: networkx/networkx/generators/directed.py
imports: import numbers
  from collections import Counter
  import networkx
  from networkx.generators.classic import empty_graph
  from networkx.utils import discrete_sequence, py_random_state, weighted_choice
label_desc: Use image node_id 6 for calling a global function with example usage: random_k_out_graph(n, k, alpha, _loops, seed) and returns: G