We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7a10a2f commit 41dfe7dCopy full SHA for 41dfe7d
micall/utils/stable_random_distribution.py
@@ -3,16 +3,17 @@
3
import numpy as np
4
5
6
-def stable_random_distribution(maximum: int) -> Iterator[int]:
+def stable_random_distribution(maximum: int, seed: int = 42) -> Iterator[int]:
7
n = maximum
8
+ rng = np.random.default_rng(seed)
9
10
weights = np.zeros(n) + 1
11
forward = np.arange(1, n + 1)
12
backwards = np.arange(n, 0, -1)
13
14
while True:
15
probabilities = weights / weights.sum()
- index = np.random.choice(n, p=probabilities)
16
+ index = rng.choice(n, p=probabilities)
17
yield index
18
weights[:index] += forward[:index]
19
weights[index:] += backwards[index:]
0 commit comments