NetworkX

Previous topic

zipf_sequence

Next topic

random_weighted_sample

zipf_rv

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

Return a random value chosen from the Zipf distribution.

The return value is an integer drawn from the probability distribution ::math:

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 : int

Seed value for random number generator

Returns :

x : int

Random value from Zipf distribution

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.

References

..[1] Luc Devroye, Non-Uniform Random Variate Generation,
Springer-Verlag, New York, 1986. http://cg.scs.carleton.ca/~luc/rnbookindex.html

Examples

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