Skip to content

Commit d39b85f

Browse files
Chihiro2000GitHubclaudeHumphreyYang
authored
Update rng usage in rand_resp.md (#891)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Humphrey Yang <39026988+HumphreyYang@users.noreply.github.com>
1 parent 7c6396a commit d39b85f

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lectures/rand_resp.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ class Comparison:
226226
A = self.A
227227
n = self.n
228228
df = self.template.copy()
229-
np.random.seed(seed)
230-
sample = np.random.rand(size, self.n) <= A
231-
random_device = np.random.rand(size, n)
229+
rng = np.random.default_rng(seed)
230+
sample = rng.random((size, self.n)) <= A
231+
random_device = rng.random((size, n))
232232
mse_rd = {}
233233
for p in self.p_arr:
234234
spinner = random_device <= p
@@ -237,8 +237,8 @@ class Comparison:
237237
pi_hat = (p - 1) / (2 * p - 1) + n1 / n / (2 * p - 1)
238238
mse_rd[p] = np.sum((pi_hat - A)**2)
239239
for inum, irow in df.iterrows():
240-
truth_a = np.random.rand(size, self.n) <= irow.T_a
241-
truth_b = np.random.rand(size, self.n) <= irow.T_b
240+
truth_a = rng.random((size, self.n)) <= irow.T_a
241+
truth_b = rng.random((size, self.n)) <= irow.T_b
242242
trad_answer = sample * truth_a + (1 - sample) * (1 - truth_b)
243243
pi_trad = trad_answer.sum(axis=1) / n
244244
df.loc[inum, 'Bias'] = pi_trad.mean() - A

0 commit comments

Comments
 (0)