@@ -126,7 +126,7 @@ def plot_normal_cdf(rbound=None, lbound=None, mean=0, sd=1):
126126plot_cdf_area = plot_normal_cdf
127127
128128
129- def sample_proportions (sample_size : int , probabilities ):
129+ def sample_proportions (sample_size : int , probabilities , seed = None ):
130130 """Return the proportion of random draws for each outcome in a distribution.
131131
132132 This function is similar to np.random.Generator.multinomial, but returns proportions
@@ -137,15 +137,17 @@ def sample_proportions(sample_size: int, probabilities):
137137
138138 ``probabilities``: An array of probabilities that forms a distribution.
139139
140+ ``seed``: Optional seed for reproducibility. If None, results will be random.
141+
140142 Returns:
141143 An array with the same length as ``probability`` that sums to 1.
142144 """
143- rng = np .random .default_rng ()
145+ rng = np .random .default_rng (seed )
144146 return rng .multinomial (sample_size , probabilities ) / sample_size
145147
146148
147149def proportions_from_distribution (table , label , sample_size ,
148- column_name = 'Random Sample' ):
150+ column_name = 'Random Sample' , seed = None ):
149151 """
150152 Adds a column named ``column_name`` containing the proportions of a random
151153 draw using the distribution in ``label``.
@@ -165,6 +167,8 @@ def proportions_from_distribution(table, label, sample_size,
165167 ``column_name``: The name of the new column that contains the sampled
166168 proportions. Defaults to ``'Random Sample'``.
167169
170+ ``seed``: Optional seed for reproducibility. If None, results will be random.
171+
168172 Returns:
169173 A copy of ``table`` with a column ``column_name`` containing the
170174 sampled proportions. The proportions will sum to 1.
@@ -173,8 +177,8 @@ def proportions_from_distribution(table, label, sample_size,
173177 ``ValueError``: If the ``label`` is not in the table, or if
174178 ``table.column(label)`` does not sum to 1.
175179 """
176- proportions = sample_proportions (sample_size , table .column (label ))
177- return table .with_column ('Random Sample' , proportions )
180+ proportions = sample_proportions (sample_size , table .column (label ), seed )
181+ return table .with_column (column_name , proportions )
178182
179183
180184def table_apply (table , func , subset = None ):
0 commit comments