diff options
| author | Jarrod Millman <jarrod.millman@gmail.com> | 2020-07-09 23:12:10 -0700 |
|---|---|---|
| committer | Jarrod Millman <jarrod.millman@gmail.com> | 2020-07-10 09:44:54 -0700 |
| commit | b22d6b36ce0545995c99d233546e8a1fe7e27fc5 (patch) | |
| tree | 9078401c2f4a7b463a82378a734508e16ef34867 /networkx/utils/random_sequence.py | |
| parent | f30e9392bef0dccbcfd1b73ccb934064f6200fa3 (diff) | |
| download | networkx-b22d6b36ce0545995c99d233546e8a1fe7e27fc5.tar.gz | |
Format w/ black
Diffstat (limited to 'networkx/utils/random_sequence.py')
| -rw-r--r-- | networkx/utils/random_sequence.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/networkx/utils/random_sequence.py b/networkx/utils/random_sequence.py index 8fb058c6..7bd68c79 100644 --- a/networkx/utils/random_sequence.py +++ b/networkx/utils/random_sequence.py @@ -11,6 +11,7 @@ from networkx.utils import py_random_state # uses Python's random module # https://docs.python.org/3/library/random.html + @py_random_state(2) def powerlaw_sequence(n, exponent=2.0, seed=None): """ @@ -73,12 +74,12 @@ def zipf_rv(alpha, xmin=1, seed=None): if alpha <= 1: raise ValueError("a <= 1.0") a1 = alpha - 1.0 - b = 2**a1 + b = 2 ** a1 while True: u = 1.0 - seed.random() # u in (0,1] v = seed.random() # v in [0,1) - x = int(xmin * u**-(1.0 / a1)) - t = (1.0 + (1.0 / x))**a1 + x = int(xmin * u ** -(1.0 / a1)) + t = (1.0 + (1.0 / x)) ** a1 if v * x * (t - 1.0) / (b - 1.0) <= t / b: break return x @@ -115,7 +116,8 @@ def discrete_sequence(n, distribution=None, cdistribution=None, seed=None): cdf = cumulative_distribution(distribution) else: raise nx.NetworkXError( - "discrete_sequence: distribution or cdistribution missing") + "discrete_sequence: distribution or cdistribution missing" + ) # get a uniform random number inputseq = [seed.random() for i in range(n)] |
