You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-16Lines changed: 14 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,9 +41,7 @@ Latest version of **PyRandLib** is version **2.0**, released by March 2025. It p
41
41
42
42
### Why not Mersenne twister?
43
43
44
-
The Mersenne twister PRNG proposed by Matsumoto and Nishimura - see [5] - is the most widely used one. The Random class of module random in Python
45
-
implements this PRNG. It is also implemented in C++ and Java standard
46
-
libraries for instance.
44
+
The Mersenne twister PRNG proposed by Matsumoto and Nishimura - see [5] - is the most widely used one. The Random class of module random in Python implements this PRNG. It is also implemented in C++ and Java standard libraries for instance.
47
45
48
46
It offers a very good period (2^19937, i.e. about 4.3e6001). Unfortunately, this PRNG is a little bit long to compute (up to 3 times than LCGs, 60% more than LFibs and a little bit less than MRGs, see below at section 'Architecture overview'). Moreover, it fails four of the hardest TestU01 tests. You can still use it as your preferred PRNG but **PyRandLib** implements many other PRNGs that are either far faster or far better in terms of generated pseudo-randomness than the Mersenne twister PRNG.
49
47
@@ -596,28 +594,28 @@ Since the base class **BaseRandom** inherits from the built-in class `random.Ran
596
594
**betavariate**(self, alpha, beta)
597
595
Beta distribution.
598
596
599
-
Conditions on the parameters are alpha > 0 and beta > 0.
597
+
Conditions on the parameters are `alpha > 0` and `beta > 0`.
600
598
Returned values range between 0 and 1.
601
599
602
600
603
601
**binomialvariate**(self, n=1, p=0.5)
604
-
Binomial distribution. Return the number of successes for n independent trials with the probability of success in each trial being p:
602
+
Binomial distribution. Return the number of successes for `n` independent trials with the probability of success in each trial being `p`:
605
603
606
604
Mathematically equivalent to:
607
605
608
606
sum(random() < p for i in range(n))
609
607
610
-
The number of trials n should be a non-negative integer. The probability of success p should be between 0.0 <= p <= 1.0. The result is an integer in the range 0 <= X <= n. This built-in, method has been added since Python 3.12. **PyRandLIb** implements it also for all former versions of Python: -3.6, -3.9, -3.10, and -3.11.
608
+
The number of trials `n` should be a non-negative integer. The probability of success `p` should be between `0.0 <= p <= 1.0`. The result is an integer in the range `0 <= X <= n`. This built-in method has been added since Python 3.12. **PyRandLIb** implements it also for all former versions of Python: -3.6, -3.9, -3.10, and -3.11.
611
609
612
610
613
611
**choice**(self, seq)
614
-
Chooses a random element from a non-empty sequence. 'seq' has to be non empty.
612
+
Chooses a random element from a non-empty sequence. `seq` has to be non empty.
Returns a *k* sized list of elements chosen from the population, with replacement. If the population is empty, raises IndexError.
616
+
Returns a `k` sized list of elements chosen from the population, with replacement. If the population is empty, raises `IndexError`.
619
617
620
-
If a *weights* sequence is specified, selections are made according to the relative weights. Alternatively, if a *cum_weights* sequence is given, the selections are made according to the cumulative weights (perhaps computed using `itertools.accumulate()`).
618
+
If a `weights` sequence is specified, selections are made according to the relative weights. Alternatively, if a `cum_weights` sequence is given, the selections are made according to the cumulative weights (perhaps computed using `itertools.accumulate()`).
621
619
For example, the relative weights `[10, 5, 30, 5]` are equivalent to the cumulative weights `[10, 15, 45, 50]`.
622
620
Internally, the relative weights are converted to cumulative weights before making selections, so supplying the cumulative weights saves work.
623
621
@@ -633,7 +631,7 @@ Exponential distribution.
633
631
634
632
`lambd` is 1.0 divided by the desired mean. It should be nonzero. (The parameter should be called "lambda", but this is a reserved word in Python).
635
633
Returned values range from 0 to positive infinity if `lambd` is positive, and from negative infinity to 0 if `lambd` is negative.
636
-
Since Python 3.12, the parameter `lambd` gets a default value in this built-in method. **PyRandLib** defines then this method for all former versions of Pyhton : -3.6, -3.9, -3.10 and -3.11.
634
+
Since Python 3.12, the parameter `lambd` gets a default value in this built-in method. **PyRandLib** defines then this method for all former versions of Python : -3.6, -3.9, -3.10 and -3.11.
637
635
638
636
639
637
**gammavariate**(self, alpha, beta)
@@ -645,8 +643,8 @@ Conditions on the parameters are `alpha` > 0 and `beta` > 0.
645
643
**gauss**(self, mu, sigma)
646
644
Gaussian distribution.
647
645
648
-
mu is the mean, and sigma is the standard deviation.
649
-
This is slightly faster than the normalvariate() function.
646
+
`mu` is the mean, and `sigma` is the standard deviation.
647
+
This is slightly faster than the `normalvariate()` function.
650
648
651
649
Not thread-safe without a lock around calls.
652
650
@@ -677,7 +675,7 @@ Pareto distribution. `alpha` is the shape parameter.
677
675
678
676
679
677
**randint**(self, a, b)
680
-
Returns a random integer in range [a, b], including both end points.
678
+
Returns a random integer in range `[a, b]`, including both end points.
681
679
682
680
683
681
**randrange**(self, stop)
@@ -712,9 +710,9 @@ Restores internal state from object returned by `getstate()`.
712
710
713
711
714
712
**shuffle**(self, x, random=None)
715
-
Shuffle the sequence x in place. Returns None.
713
+
Shuffle the sequence `x` in place. Returns None.
716
714
717
-
The optional argument `random` is a 0-argument function returning a random float in [0.0, 1.0); by default, this is the function random().
715
+
The optional argument `random` is a 0-argument function returning a random float in `[0.0, 1.0)`; by default, this is the function random().
718
716
719
717
To shuffle an immutable sequence and return a new shuffled list, use `sample(x, k=len(x))` instead.
720
718
@@ -730,7 +728,7 @@ see [http://en.wikipedia.org/wiki/Triangular_distribution](http://en.wikipedia.o
730
728
731
729
732
730
**uniform**(self, a, b)
733
-
Gets a random number in the range [`a`, `b`) or [`a`, `b`] depending on rounding.
731
+
Gets a random number in the range `[a, b)` or `[a, b]` depending on rounding.
0 commit comments