K idZddlZddlmZgdZedddZedddZd Zed dd Z eddd Z eddd Z y)zS Utilities for generating random numbers, random sequences, and random selections. N)py_random_state)powerlaw_sequencezipf_rvcumulative_distributiondiscrete_sequencerandom_weighted_sampleweighted_choicecbt|Dcgc]}|j|dz c}Scc}w)zK Return sample sequence of length n from a power law distribution. )range paretovariate)nexponentseedis d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/networkx/utils/random_sequence.pyrrs+ 7`. 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. 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. r zxmin < 1za <= 1.0g?r ) ValueErrorrandomint) alphaxminra1buvxts rrr sb ax$$ z$$ B 2A  $++-  KKM qcBhK'' ( C!G_ # q5AG C (AE 1  H cdg}t|}tt|D]}|j|||||z z!|S)zFReturns normalized cumulative distribution from discrete distribution.g)sumr lenappend) distributioncdfpsumrs rrrasQ %C | D 3|$ %4 3q6LOd2234 Jr cddl}||}n#| t|}ntjdt |Dcgc]}|j }}|Dcgc]}|j ||dz } }| Scc}wcc}w)a# Return sample sequence of length n from a given discrete distribution or discrete cumulative distribution. One of the following must be specified. distribution = histogram of values, will be normalized cdistribution = normalized discrete cumulative distribution rNz8discrete_sequence: distribution or cdistribution missingr )bisectrnx NetworkXErrorr r bisect_left) rr% cdistributionrr*r&rinputseqsseqs rrrks   !%l3 F  (-Qx0! 0H04< rCs * @@= = @>    r