File tree Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Expand file tree Collapse file tree 1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,10 @@ class VoseAlias(object):
20
20
http://www.keithschwarz.com/darts-dice-coins/).
21
21
"""
22
22
23
- def __init__ (self , dist ):
24
- """ (VoseAlias, dict) -> NoneType """
23
+ def __init__ (self , dist , rng = None ):
24
+ """ (VoseAlias, dict[, RNG] ) -> NoneType """
25
25
self .dist = dist
26
+ self .rng = rng or random .Random ()
26
27
self .alias_initialisation ()
27
28
self .table_prob_list = list (self .table_prob )
28
29
@@ -68,10 +69,10 @@ def alias_initialisation(self):
68
69
def alias_generation (self ):
69
70
""" Return a random outcome from the distribution. """
70
71
# 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 )
72
73
73
74
# 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 ():
75
76
return col
76
77
else :
77
78
return self .table_alias [col ]
You can’t perform that action at this time.
0 commit comments