Skip to main content
`Ctrl`+`K`

# random_lobster

random_lobster(n, p1, p2, seed=None, *, create_using=None)

  Returns a random lobster graph.

  A lobster is a tree that reduces to a caterpillar when pruning all leaf nodes. A caterpillar is a tree that reduces to a path graph when pruning all leaf nodes; setting `p2` to zero produces a caterpillar.

  This implementation iterates on the probabilities `p1` and `p2` to add edges at levels 1 and 2, respectively. Graphs are therefore constructed iteratively with uniform randomness at each level rather than being selected uniformly at random from the set of all possible lobsters.

  Parameters:
    n int

      The expected number of nodes in the backbone

    p1 float

      Probability of adding an edge to the backbone

    p2 float

      Probability of adding an edge one level beyond backbone

    seed integer, random_state, or None (default)

      Indicator of random number generation state. See Randomness.

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

      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 `p1` or `p2` parameters are >= 1 because the while loops would never finish.