� !A?h�}��t�dZddlmZddlmZmZm Z m Z m ZddlmZmZmZmZddlmZmZmZddlmZddl m!Z"m#Z$ddl%m&Z'dd l(m)Z*m+Z,dd l-m-Z.dd lZ/dd l0Z0 dd l1m2Z1n#e3$r dd l4m2Z1YnwxYwgd �Z5ded��zed��z Z6ed��Z7ded��zZ8dZ9de9 zZ:dZ;Gd�de0j<��Z<Gd�de<��Z=e<��Z>e>j?Z?e>j@Z@e>jAZAe>jBZBe>jCZCe>jDZDe>jEZEe>jFZFe>jGZGe>jHZHe>jIZIe>jJZJe>jKZKe>jLZLe>jMZMe>jNZNe>jOZOe>jPZPe>jQZQe>jRZRe>jSZSe>jTZTe>jUZUd�ZVd!d�ZWeXe/d��re/jYe>j?���eZd kr eW��d Sd S)"a�Random variable generators. bytes ----- uniform bytes (values between 0 and 255) integers -------- uniform within range sequences --------- pick random element pick random sample pick weighted random sample generate random permutation distributions on the real line: ------------------------------ uniform triangular normal (Gaussian) lognormal negative exponential gamma beta pareto Weibull distributions on the circle (angles 0 to 2pi) --------------------------------------------- circular uniform von Mises General notes on the underlying Mersenne Twister core generator: * The period is 2**19937-1. * It is one of the most extensively tested generators in existence. * The random() method is implemented in C, executes in a single Python step, and is, therefore, threadsafe. �)�warn)�log�exp�pi�e�ceil)�sqrt�acos�cos�sin)�tau�floor�isfinite)�urandom)�Set�Sequence)�index)� accumulate�repeat)�bisectN)�sha512)�Random� SystemRandom� betavariate�choice�choices� expovariate� gammavariate�gauss� getrandbits�getstate�lognormvariate� normalvariate� paretovariate� randbytes�randint�random� randrange�sample�seed�setstate�shuffle� triangular�uniform�vonmisesvariate�weibullvariate�g��@�@��?�@�5��c����eZdZdZdZd&d�Zd'�fd� Z�fd�Z�fd�Zd �Z d �Z d �Z d �Z d �Z dezfd�Ze Zd�Zdefd�Zd�Zd�Zd�Zdd�d�Zd&ddd�d�Zd�Zd(d�Zd)d�Zd)d�Zd�Zd �Zd!�Zd"�Z d#�Z!d$�Z"d%�Z#�xZ$S)*ra�Random number generator base class used by bound module functions. Used to instantiate instances of Random to get generators that don't share state. Class Random can also be subclassed if you want to use a different basic generator of your own devising: in that case, override the following methods: random(), seed(), getstate(), and setstate(). Optionally, implement a getrandbits() method so that randrange() can cover arbitrarily large ranges. �Nc�>�|�|��d|_dS)zeInitialize an instance. Optional argument x controls seeding, as for Random.seed(). N)r*� gauss_next)�self�xs �3/opt/alt/python-internal/lib64/python3.11/random.py�__init__zRandom.__init__ws�� � � �!� � � ������r7c �^��|dkr�t|ttf��r�t|t��r|�d��n|}|rt |d��dznd}t t|��D] }d|z|z dz}�|t |��z}|dkrdn|}n�|d kr�t|tttf��rft|t��r|���}t� |t|��� ��z��}nKt|td ��tttttf��std ���t!���|��d |_d S) a\Initialize internal state from a seed. The only supported seed types are None, int, float, str, bytes, and bytearray. None or no argument seeds from current time or from an operating system specific randomness source if available. If *a* is an int, all bits are used. For version 2 (the default), all of the bits are used if *a* is a str, bytes, or bytearray. For version 1 (provided for reproducing random sequences from older versions of Python), the algorithm for str and bytes generates a narrower range of seeds. r8zlatin-1r�iCBl��������������r7NzOThe only supported seed types are: None, int, float, str, bytes, and bytearray.)� isinstance�str�bytes�decode�ord�map�len� bytearray�encode�int� from_bytes�_sha512�digest�type�float� TypeError�superr*r<)r=�a�versionr>�c� __class__s �r?r*z Random.seed�sx���$ �a�<�<�J�q�3��,�7�7�<�'1�!�U�';�';�B�����#�#�#��A�"#�*��A�a�D� � �Q����A���a�[�[� =� =����k�Q�&�*<�<��� ��Q���K�A��2�g�g���1�A�A� ��\�\�j��S�%��,C�D�D�\��!�S�!�!� ��H�H�J�J�����q�7�1�:�:�#4�#4�#6�#6�6�7�7�A�A��A��T� � �C���U�I�N�O�O� F��E�F�F� F� ��� � �Q��������rAc�^��|jt�����|jfS)z9Return internal state; can be passed to setstate() later.)�VERSIONrVr!r<)r=rZs �r?r!zRandom.getstate�s$����|�U�W�W�-�-�/�/���@�@rAc���|d}|dkr.|\}}|_t���|��dS|dkrc|\}}|_ td�|D����}n#t$r }t |�d}~wwxYwt���|��dSt d|�d|j�����)z:Restore internal state from object returned by getstate().rr:r7c3� K�|] }|dzV�� dS)lN�)�.0r>s r?� z"Random.setstate..�s&����%K�%K��a�7�m�%K�%K�%K�%K�%K�%KrANzstate with version z( passed to Random.setstate() of version )r<rVr+�tuple� ValueErrorrUr\)r=�staterX� internalstaterrZs �r?r+zRandom.setstate�s������(�� �a�<�<�6;� 3�G�]�D�O� �G�G� � �]� +� +� +� +� +� ��\�\�6;� 3�G�]�D�O�  '� %�%K�%K�]�%K�%K�%K� K� K� � ��� '� '� '��Q�&����� '���� �G�G� � �]� +� +� +� +� +��*�%�g�g�t�|�|�5�6�6� 6s�A*�* B�4A<�<Bc�*�|���S�N)r!�r=s r?� __getstate__zRandom.__getstate__�s���}�}���rAc�0�|�|��dSrg)r+)r=rds r?� __setstate__zRandom.__setstate__�s�� � � �e�����rAc�:�|jd|���fS)Nr_)rZr!rhs r?� __reduce__zRandom.__reduce__�s���~�r�4�=�=�?�?�2�2rAc ��|jD]>}d|jvrdSd|jvr|j|_dSd|jvr|j|_dS�?dS)aControl how subclasses generate random integers. The algorithm a subclass can use depends on the random() and/or getrandbits() implementation available to it and determines whether it can generate random integers from arbitrarily large ranges. � _randbelowr r'N)�__mro__�__dict__�_randbelow_with_getrandbitsro�_randbelow_without_getrandbits)�cls�kwargsrYs r?�__init_subclass__zRandom.__init_subclass__�st���� � �A��q�z�)�)������ �*�*�!$�!@�������1�:�%�%�!$�!C������&� � rAc��|j}|���}||��}||kr||��}||k�|S)z;Return a random int in the range [0,n). Defined for n > 0.)r � bit_length)r=�nr �k�rs r?rrz"Random._randbelow_with_getrandbits�sL���&� � �L�L�N�N�� �K��N�N���1�f�f�� �A���A��1�f�f��rAr8c���|j}||kr)td��t|��|z��S||z}||z |z }|��}||kr|��}||k�t||z��|zS)z�Return a random int in the range [0,n). Defined for n > 0. The implementation does not use getrandbits, but only random. z�Underlying random() generator does not supply enough bits to choose from a population range this large. To remove the range limitation, add a getrandbits() method.)r'�_warn�_floor)r=ry�maxsizer'�rem�limitr{s r?rsz%Random._randbelow_without_getrandbits�s��� ��� ��<�<� �N� O� O� O��&�&�(�(�Q�,�'�'� '���k���3��'�)�� �F�H�H���5�j�j�����A��5�j�j��a�'�k�"�"�Q�&�&rAc�Z�|�|dz���|d��S)�Generate n random bytes.��little)r �to_bytes�r=rys r?r%zRandom.randbytess*������A��&�&�/�/��8�<�<�� randbelow�i�js r?r,zRandom.shufflexsl���O� ��%��3�q�6�6�*�*�+�+� $� $�A�� �!�a�%� � �A��1��q��t�J�A�a�D�!�A�$�$� $� $rA)�countsc�����t�t��std���t���}|��t t |�����t���|krt d�������}t|t��std���|dkrt d���|� t|��|���}t����fd�|D��S|j }d|cxkr|ksnt d ���dg|z}d } |d kr&| d tt|d zd ����zz } || krLt ���} t|��D],} ||| z ��} | | || <| || z dz | | <�-n[t��} | j}t|��D]6} ||��} | | vr||��} | | v�|| ���| || <�7|S)afChooses k unique random elements from a population sequence. Returns a new list containing elements from the population while leaving the original population unchanged. The resulting list is in selection order so that all sub-slices will also be valid random samples. This allows raffle winners (the sample) to be partitioned into grand prize and second place winners (the subslices). Members of the population need not be hashable or unique. If the population contains repeats, then each occurrence is a possible selection in the sample. Repeated elements can be specified one at a time or with the optional counts parameter. For example: sample(['red', 'blue'], counts=[4, 2], k=5) is equivalent to: sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5) To choose a sample from a range of integers, use range() for the population argument. This is especially fast and space efficient for sampling from a large population: sample(range(10000000), 60) zAPopulation must be a sequence. For dicts or sets, use sorted(d).Nz2The number of counts does not match the populationzCounts must be integersrz)Total of counts must be greater than zero)rzc�4��g|]}���|����Sr_r_)r`�sr� cum_counts� populations ���r?� z!Random.sample..�s*���J�J�J�!�J�v�v�j�!�4�4�5�J�J�JrAz,Sample larger than population or is negative��r1r:r8)rF� _SequencerUrL�list� _accumulaterc�poprOr)r��_bisectro�_ceil�_log�set�add)r=r�rzr�ry�total� selectionsr��result�setsize�poolr�r��selected� selected_addrr�s ` @@r?r)z Random.sample�sL�����j�*�i�0�0� A��@�A�A� A� � �O�O�� � ��k�&�1�1�2�2�J��:���!�#�#� �!U�V�V�V��N�N�$�$�E��e�S�)�)� ;�� 9�:�:�:���z�z� �!L�M�M�M����U�5�\�\�Q��7�7�J��F�J�J�J�J�J�J�z�J�J�J� J��O� ��A�{�{�{�{��{�{�{�{��K�L�L� L���!����� �q�5�5� �q�E�$�q�1�u�a�.�.�1�1�1� 1�G� ��<�<�� �#�#�D��1�X�X� *� *���I�a�!�e�$�$�� ��G��q� ��q�1�u�q�y�/��Q��� *� �u�u�H�#�<�L��1�X�X� *� *���I�a�L�L���8�m�m�!� �!� � �A��8�m�m�� �Q����&�q�M��q� � �� rA)� cum_weightsrzc�������� � �|j� t�������|�+t��dz ����� fd�td|��D��S t t |�����nJ#t $r,t|t��s�|}t d|����d�wxYw|�t d���t����krtd����ddz� � dkrtd���t� ��std ���t��d z ������ � fd �td|��D��S) z�Return a k sized list of population elements chosen with replacement. If the relative weights or cumulative weights are not specified, the selections are made with equal probability. N�c�H��g|]}������z����Sr_r_)r`r�rryr�r's ����r?r�z"Random.choices..�s2���R�R�R�A� �5�5�����A��#6�#6�7�R�R�RrAz4The number of choices must be a keyword argument: k=z2Cannot specify both weights and cumulative weightsz3The number of weights does not match the populationrDz*Total of weights must be greater than zerozTotal of weights must be finiter8c �N��g|]!}�������zd�����"S)rr_)r`r�rr��hir�r'r�s ������r?r�z"Random.choices..sI���+�+�+���6�6�+�v�v�x�x�%�/?��B�G�G�H�+�+�+rA) r'rLr~�_repeatr�r�rUrFrOrc� _isfiniter�) r=r��weightsr�rzrrr�ryr'r�s ` ` @@@@@@r?rzRandom.choices�s�������������� � �O�O�� � ������S���R�R�R�R�R�R�R���q�AQ�AQ�R�R�R�R� �"�;�w�#7�#7�8�8� � ��� � � �!�'�3�/�/������M��M�M�����  ����� ��P�Q�Q� Q� �{� � �q� � ��R�S�S� S��B��#�%�� �C�<�<��I�J�J� J����� @��>�?�?� ?��� ��U��+�+�+�+�+�+�+�+�+� ��q�)�)�+�+�+� +s �A,�,6B"c�<�|||z |���zzS)zHGet a random number in the range [a, b) or [a, b] depending on rounding.�r'r�s r?r.zRandom.uniforms���A��E�T�[�[�]�]�*�*�*rAr�r4c���|���} |�dn ||z ||z z }n#t$r|cYSwxYw||krd|z }d|z }||}}|||z t||z��zzS)z�Triangular distribution. Continuous distribution bounded by given lower and upper limits, and having a given mode value in-between. http://en.wikipedia.org/wiki/Triangular_distribution N��?r4)r'�ZeroDivisionError�_sqrt)r=�low�high�mode�urYs r?r-zRandom.triangular s��� �K�K�M�M�� ��|���$��*����)D�A�A�� � � � ��J�J�J� ���� �q�5�5��a��A��a��A��c��C��d�S�j�E�!�a�%�L�L�0�0�0s �&� 5�5c��|j} |��}d|��z }t|dz z|z }||zdz }|t|�� krn�E|||zzS)z\Normal distribution. mu is the mean, and sigma is the standard deviation. Tr4r�r3)r'� NV_MAGICCONSTr�)r=�mu�sigmar'�u1�u2�z�zzs r?r#zRandom.normalvariate ss����� �����B��v�v�x�x��B���c��*�R�/�A��Q����B��d�2�h�h�Y����  ��A��I�~�rAc� �|j}|j}d|_|�e|��tz}tdt d|��z ��z��}t |��|z}t |��|z|_|||zzS)z�Gaussian distribution. mu is the mean, and sigma is the standard deviation. This is slightly faster than the normalvariate() function. Not thread-safe without a lock around calls. Ng�r4)r'r<�TWOPIr�r��_cos�_sin)r=r�r�r'r��x2pi�g2rads r?rz Random.gauss5s���6��� �O����� �9��6�8�8�e�#�D��$��c�F�F�H�H�n�!5�!5�5�6�6�E��T� � �U�"�A�"�4�j�j�5�0�D�O��A��I�~�rAc�H�t|�||����S)z�Log normal distribution. If you take the natural logarithm of this distribution, you'll get a normal distribution with mean mu and standard deviation sigma. mu can have any value, and sigma must be greater than zero. )�_expr#)r=r�r�s r?r"zRandom.lognormvariate[s"���D�&�&�r�5�1�1�2�2�2rAc�R�td|���z �� |z S)a^Exponential distribution. lambd is 1.0 divided by the desired mean. It should be nonzero. (The parameter would be called "lambda", but that is a reserved word in Python.) Returned values range from 0 to positive infinity if lambd is positive, and from negative infinity to 0 if lambd is negative. r4)r�r')r=�lambds r?rzRandom.expovariatees'���S�4�;�;�=�=�(�)�)�)�E�1�1rAc���|j}|dkrt|��zSd|z }|td||zz��z} |��}tt|z��}|||zz }|��} | d||zz ks| d|z t |��zkrn�Zd|z } | |zd| |zzz } |��} | dkr|t | ��ztz} n|t | ��z tz} | S)aFCircular data distribution. mu is the mean angle, expressed in radians between 0 and 2*pi, and kappa is the concentration parameter, which must be greater than or equal to zero. If kappa is equal to zero, this distribution reduces to a uniform random angle over the range 0 to 2*pi. g�����ư>r�r4)r'r�r�r��_pir��_acos)r=r��kappar'r�r{r�r��dr��q�f�u3�thetas r?r/zRandom.vonmisesvariatevs�� ��� �D�=�=��6�6�8�8�#� #� �%�K�� ��c�A��E�k�"�"� "�� �����B��S�2�X���A��Q��U� �A�����B��C�!�a�%�K���2�#��'�T�!�W�W�)<�#<�#<�� � �!�G�� ��U�s�Q��U�{� #�� �V�X�X�� ��8�8��%��(�(�]�e�+�E�E��%��(�(�]�e�+�E�� rAc��|dks|dkrtd���|j}|dkr�td|zdz ��}|tz }||z} |��}d|cxkrdksn�d|��z }t |d|z z ��|z } |t | ��z} ||z|z} ||| zz| z } | t zd| zz dks| t | ��kr| |zS��|dkrt d|��z �� |zS |��} t|ztz }|| z}|dkr |d|z z} nt ||z |z �� } |��}|dkr|| |dz zkrnn|t | ��krn�z| |zS) aZGamma distribution. Not the gamma function! Conditions on the parameters are alpha > 0 and beta > 0. The probability distribution function is: x ** (alpha - 1) * math.exp(-x / beta) pdf(x) = -------------------------------------- math.gamma(alpha) * beta ** alpha r�z*gammavariate: alpha and beta must be > 0.0r4r2TgH�����z>g�P����?r5)rcr'r��LOG4r�r�� SG_MAGICCONST�_e)r=�alpha�betar'�ainv�bbb�cccr�r��vr>r�r{r�r��ps r?rzRandom.gammavariate�s��� �C�<�<�4�3�;�;��I�J�J� J���� �3�;�;� ��u��s�*�+�+�D��$�,�C��$�,�C� $��V�X�X���b�,�,�,�,�9�,�,�,�,���6�6�8�8�^����s�R�x��)�)�D�0���D��G�G�O����G�b�L���#��'�M�A�%���}�$�s�Q�w�.�#�5�5��d�1�g�g����t�8�O� $��c�\�\���v�v�x�x��(�(�(�4�/� /� ��F�H�H���%�Z�2�%����E����8�8��c�E�k�*�A�A��q�1�u��o�.�.�.�A��V�X�X���s�7�7��Q�5�3�;�/�/�/��0��4���8�8�^�^�� ��t�8�OrAc�n�|�|d��}|r|||�|d��zz SdS)z�Beta distribution. Conditions on the parameters are alpha > 0 and beta > 0. Returned values range between 0 and 1. r4r�)r)r=r�r��ys r?rzRandom.betavariate�sF��, � � �e�S� )� )�� � :���D�-�-�d�C�8�8�8�9� 9��srAc�@�d|���z }|d|z zS)z3Pareto distribution. alpha is the shape parameter.r4g�r�)r=r�r�s r?r$zRandom.paretovariate�s%�� �$�+�+�-�-� ���T�E�\�"�"rAc�b�d|���z }|t|�� d|z zzS)zfWeibull distribution. alpha is the scale parameter and beta is the shape parameter. r4)r'r�)r=r�r�r�s r?r0zRandom.weibullvariates2�� �$�+�+�-�-� ����a����c�D�j�1�1�1rArg)Nr7)r�r4N�r�r4)%�__name__� __module__� __qualname__�__doc__r\r@r*r!r+rirkrmrvrr�BPFrsror%r�r(r&rr,r)rr.r-r#rr"rr/rrr$r0� __classcell__)rZs@r?rrgsd������� � ��G�����$�$�$�$�$�$�LA�A�A�A�A�6�6�6�6�6�B������3�3�3� ���(���9:�3��'�'�'�'�&-�J�=�=�=�%)�t�H3�H3�H3�H3�T&�&�&�.�.�.�$�$�$�/3�]�]�]�]�]�~#+�t�q�#+�#+�#+�#+�#+�P+�+�+�1�1�1�1�(����*$�$�$�$�L3�3�3�2�2�2�"(�(�(�T?�?�?�B���6#�#�#� 2� 2� 2� 2� 2� 2� 2rArc�8�eZdZdZd�Zd�Zd�Zd�Zd�ZexZ Z dS)rz�Alternate random number generator using sources provided by the operating system (such as /dev/urandom on Unix or CryptGenRandom on Windows). Not available on all systems (see os.urandom() for details). c�f�t�td����dz tzS)z7Get the next random number in the range 0.0 <= X < 1.0.rCr:)rOrP�_urandom� RECIP_BPFrhs r?r'zSystemRandom.randoms$�����x��{�{�+�+�q�0�I�=�=rAc��|dkrtd���|dzdz}t�t|����}||dz|z z S)z:getrandbits(k) -> x. Generates an int with k random bits.rz#number of bits must be non-negativerCr�)rcrOrPr�)r=rz�numbytesr>s r?r zSystemRandom.getrandbits sT�� �q�5�5��B�C�C� C���E�a�<�� �N�N�8�H�-�-� .� .���X��\�A�%�&�&rAc� �t|��S)r�)r�r�s r?r%zSystemRandom.randbytes(s����{�{�rAc��dS)z�>�>�'�'�'���� ���P�P�P�*�)�H�x�x�xrArc�^���ddlm}m}ddlm}|��}��fd�t d|��D��}|��}||��} ||| ��} t |��} t|��} t||z d�d|�d�j ����td| | | | fz��dS) Nr)�stdev�fmean)� perf_counterc���g|]}�����Sr_r_)r`r�r�funcs ��r?r�z#_test_generator..as��� 2� 2� 2�A�D�D�$�K� 2� 2� 2rAz.3fz sec, z times z"avg %g, stddev %g, min %g, max %g ) � statisticsr r �timer r��min�max�printr�) ryrrr �meanr �t0�data�t1�xbarr�r�r�s `` r?�_test_generatorr\s�����/�/�/�/�/�/�/�/�!�!�!�!�!�!� ����B� 2� 2� 2� 2� 2���q�!1�!1� 2� 2� 2�D� ����B� �4��:�:�D� �E�$�� � �E� �d�)�)�C� �t�9�9�D� �R�"�W� 9� 9� 9�� 9� 9�$�-� 9� 9�:�:�:� � /�4���T�2J� J�K�K�K�K�KrA��c���t|td��t|td��t|td��t|td��t|t d��t|t d��t|t d��t|t d��t|t d��t|t d��t|t d ��t|t d ��t|t d ��t|t d��t|td ��t|td ��dS)Nr_r�)g{�G�z�?r4)皙�����?r4)rr2)r�r4)g�������?r4)r4r4)r2r4)g4@r4)gi@r4)�@r)r�r4gUUUUUU�?) rr'r#r"r/rrrr-)�Ns r?�_testr ms)���A�v�r�"�"�"��A�}�j�1�1�1��A�~�z�2�2�2��A�� �3�3�3��A�|�[�1�1�1��A�|�Z�0�0�0��A�|�Z�0�0�0��A�|�Z�0�0�0��A�|�Z�0�0�0��A�|�Z�0�0�0��A�|�Z�0�0�0��A�|�[�1�1�1��A�|�\�2�2�2��A�u�j�)�)�)��A�{�J�/�/�/��A�z�#8�9�9�9�9�9rA�fork)�after_in_child�__main__)r)[r��warningsrr}�mathrr�rr�rr�rr�rr�r r�r r�r r�r r�r r�rr~rr��osrr��_collections_abcr�_Setrr��operatorrr�� itertoolsrr�rr�rr��_os�_randomrQr� ImportError�hashlib�__all__r�r�r�r�r�r�rr�_instr*r'r.r-r&rr(r)r,rr#r"rr/rrrr$r0r!r+r r%rr �hasattr�register_at_forkr�r_rAr?�r3sL��)�)�^#�"�"�"�"�"�L�L�L�L�L�L�L�L�L�L�L�L�L�L�G�G�G�G�G�G�G�G�G�G�G�G�E�E�E�E�E�E�E�E�E�E�"�"�"�"�"�"�?�?�?�?�?�?�?�?�$�$�$�$�$�$�B�B�B�B�B�B�B�B�$�$�$�$�$�$���������*�)�)�)�)�)�)�)���*�*�*�)�)�)�)�)�)�)�)�*���� � � ��8�D�D��J�J����s���+� � �t�C�y�y���d�d�3�i�i�� ��� �#��I� ���e 2�e 2�e 2�e 2�e 2�W�^�e 2�e 2�e 2�X"*�"*�"*�"*�"*�6�"*�"*�"*�X ����� �z�� ��� �-�� � � � �-�� ��� �O� � ��� �-�� �-���#� ��%���� ��'���!� � � ���� ��#� ��%�� �>�� �>���� � �O� � L�L�L�":�:�:�:�, �7�3����4��C��� �3�3�3�3� �z��� �E�G�G�G�G�G��s�A� A-�,A-