ó
    êZh�  ã                   óÊ   • S r SSKrSSKJr  / SQr\" S5      SS j5       r\" S5      SS j5       rS	 r\" S
5      SS j5       r	\" S5      SS j5       r
\" S5      SS j5       rg)zS
Utilities for generating random numbers, random sequences, and
random selections.
é    N)Úpy_random_state)Úpowerlaw_sequenceÚzipf_rvÚcumulative_distributionÚdiscrete_sequenceÚrandom_weighted_sampleÚweighted_choiceé   c                 óf   • [        U 5       Vs/ s H  o2R                  US-
  5      PM     sn$ s  snf )zC
Return sample sequence of length n from a power law distribution.
é   )ÚrangeÚparetovariate)ÚnÚexponentÚseedÚis       Úk/home/gothic/public_html/Fooocus/fooocus_env/lib/python3.13/site-packages/networkx/utils/random_sequence.pyr   r      s-   € ô
 7<¸A´hÓ?²h°×Ñ˜x¨!™|Ö,±hÑ?Ð?ùÒ?s   Ž.r   c                 ó  • US:  a  [        S5      eU S::  a  [        S5      eU S-
  nSU-  n SUR                  5       -
  nUR                  5       n[        XSU-  * -  -  5      nSSU-  -   U-  nXg-  US-
  -  US-
  -  X„-  ::  a   U$ M]  )aç  Returns 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 : integer, random_state, or None (default)
    Indicator of random number generation state.
    See :ref:`Randomness<randomness>`.

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   zxmin < 1za <= 1.0g      ð?r
   )Ú
ValueErrorÚrandomÚint)	ÚalphaÚxminr   Úa1ÚbÚuÚvÚxÚts	            r   r   r       s®   € ðb ˆaƒxÜ˜Ó$Ð$Ø�ƒzÜ˜Ó$Ð$Ø	�‰€BØ	ˆ2‰€AØ
Ø�$—+‘+“-ÑˆØ�K‰K‹MˆÜ�˜c B™h˜KÑ'Ñ'Ó(ˆØ�C˜!‘G‰_ Ñ#ˆØ‰5�A˜‘GÑ  C¡Ñ(¨A©EÓ1ØØ€Hñ ó    c                 óŽ   • S/n[        U 5      n[        [        U 5      5       H  nUR                  X   X   U-  -   5        M      U$ )zFReturns normalized cumulative distribution from discrete distribution.g        )Úsumr   ÚlenÚappend)ÚdistributionÚcdfÚpsumr   s       r   r   r   a   sH   € ð ˆ%€CÜˆ|Ó€DÜ”3�|Ó$Ö%ˆØ�
‰
�3‘6˜L™O¨dÑ2Ñ2Ö3ñ &à€Jr    é   c                 ó  • SSK nUb  UnO%Ub  [        U5      nO[        R                  " S5      e[	        U 5       Vs/ s H  ocR                  5       PM     nnU Vs/ s H  o„R                  XX5      S-
  PM     n	nU	$ s  snf s  snf )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

r   Nz8discrete_sequence: distribution or cdistribution missingr   )Úbisectr   ÚnxÚNetworkXErrorr   r   Úbisect_left)
r   r%   Úcdistributionr   r*   r&   r   ÚinputseqÚsÚseqs
             r   r   r   k   s‰   € ó àÑ Ø‰Ø	Ñ	!Ü% lÓ3‰ä×ÒØFó
ð 	
ô
 (-¨Q¤xÓ0¢x !—‘–¡x€HÐ0ñ 4<Ó
<²8¨a×Ñ˜cÓ%¨Ô)±8€CÐ
<Ø€Jùò	 1ùò =s   ½A=ÁBc                 óÔ   • U[        U 5      :”  a  [        S5      e[        5       n[        U5      U:  a+  UR                  [	        X5      5        [        U5      U:  a  M+  [        U5      $ )zxReturns k items without replacement from a weighted sample.

The input is a dictionary of items with weights as values.
zsample larger than population)r#   r   ÚsetÚaddr	   Úlist)ÚmappingÚkr   Úsamples       r   r   r   ‹   sV   € ð 	Œ3ˆw‹<ÓÜÐ8Ó9Ð9Ü‹U€FÜ
ˆf‹+˜‹/Ø�
‰
”? 7Ó1Ô2ô ˆf‹+˜�/ä�‹<Ðr    c                 ó¦   • UR                  5       [        U R                  5       5      -  nU R                  5        H  u  p4X$-  nUS:  d  M  Us  $    g)zmReturns a single element from a weighted sample.

The input is a dictionary of items with weights as values.
r   N)r   r"   ÚvaluesÚitems)r6   r   Úrndr7   Úws        r   r	   r	   ™   sE   € ð �+‰+‹-œ#˜gŸn™nÓ.Ó/Ñ
/€CØ—‘–‰ˆØ‰ˆØ��7ØŠHò  r    )g       @N)r   N)NNN)N)Ú__doc__Únetworkxr+   Únetworkx.utilsr   Ú__all__r   r   r   r   r   r	   © r    r   Ú<module>rC      sž   ðñó
 Ý *ò€ñ �Óó@ó ð@ñ �Óó=ó ð=ò@ñ �Óóó ðñ> �Óó
ó ð
ñ �Óó
ó ñ
r    