Skip to content

Commit 137b1fc

Browse files
authored
Merge branch 'main' into patch-2
2 parents 67ae3ac + f7bf053 commit 137b1fc

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

vose_sampler/vose_sampler.py

100755100644
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class VoseAlias(object):
2020
http://www.keithschwarz.com/darts-dice-coins/).
2121
"""
2222

23-
def __init__(self, dist):
24-
""" (VoseAlias, dict) -> NoneType """
23+
def __init__(self, dist, rng=None):
24+
""" (VoseAlias, dict[, RNG]) -> NoneType """
2525
self.dist = dist
26+
self.rng = rng or random.Random()
2627
self.alias_initialisation()
2728
self.table_prob_list = list(self.table_prob)
2829

@@ -68,10 +69,10 @@ def alias_initialisation(self):
6869
def alias_generation(self):
6970
""" Return a random outcome from the distribution. """
7071
# Determine which column of table_prob to inspect
71-
col = random.choice(self.table_prob_list)
72+
col = self.rng.choice(self.table_prob_list)
7273

7374
# Determine which outcome to pick in that column
74-
if self.table_prob[col] >= random.random():
75+
if self.table_prob[col] >= self.rng.random():
7576
return col
7677
else:
7778
return self.table_alias[col]

0 commit comments

Comments
 (0)