networkx.utils.random_sequence.zipf_rv

zipf_rv(alpha, xmin=1, seed=None)[source]

Returns a random value chosen from the Zipf distribution.

The return value is an integer drawn from the probability distribution

\[p(x)=\frac{x^{-\alpha}}{\zeta(\alpha, x_{\min})},\]

where \(\zeta(\alpha, x_{\min})\) is the Hurwitz zeta function.

Parameters
  • alpha (float) – Exponent value of the distribution

  • xmin (int) – Minimum value

  • seed (integer, random_state, or None (default)) – Indicator of random number generation state. See Randomness.

Returns

x – Random value from Zipf distribution

Return type

int

Raises

ValueError: – If xmin < 1 or If alpha <= 1

Notes

The rejection algorithm generates random values for a the power-law distribution in uniformly bounded expected time dependent on parameters. See 1 for details on its operation.

Examples

>>> nx.utils.zipf_rv(alpha=2, xmin=3, seed=42)
8

References

1

Luc Devroye, Non-Uniform Random Variate Generation, Springer-Verlag, New York, 1986.