Skip to main content
`Ctrl`+`K`

# random_powerlaw_tree

random_powerlaw_tree(n, gamma=3, seed=None, tries=100, *, create_using=None)

  Returns a tree with a power law degree distribution.

  Parameters:
    n int

      The number of nodes.

    gamma float

      Exponent of the power law.

    seed integer, random_state, or None (default)

      Indicator of random number generation state. See Randomness.

    tries int

      Number of attempts to adjust the sequence to make it a tree.

    create_using Graph constructor, optional (default=nx.Graph)

      Graph type to create. If graph instance, then cleared before populated. Multigraph and directed types are not supported and raise a `NetworkXError`.

  Raises:
    NetworkXError

      If no valid sequence is found within the maximum number of attempts.

  Notes

  A trial power law degree sequence is chosen and then elements are swapped with new elements from a powerlaw distribution until the sequence makes a tree (by checking, for example, that the number of edges is one smaller than the number of nodes).