Skip to content

Commit ab687aa

Browse files
Update rng usage in perm_income.md (#975)
1 parent c6d14eb commit ab687aa

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lectures/perm_income.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ r = 0.05
479479
T = 60
480480
481481
@jit
482-
def time_path(T):
483-
w = np.random.randn(T+1) # w_0, w_1, ..., w_T
482+
def time_path(T, rng):
483+
w = rng.standard_normal(T+1) # w_0, w_1, ..., w_T
484484
w[0] = 0
485485
b = np.zeros(T+1)
486486
for t in range(1, T+1):
@@ -489,7 +489,8 @@ def time_path(T):
489489
c = μ + (1 - β) * (σ * w - b)
490490
return w, b, c
491491
492-
w, b, c = time_path(T)
492+
rng = np.random.default_rng()
493+
w, b, c = time_path(T, rng)
493494
494495
fig, ax = plt.subplots(figsize=(10, 6))
495496
@@ -512,7 +513,7 @@ fig, ax = plt.subplots(figsize=(10, 6))
512513
513514
b_sum = np.zeros(T+1)
514515
for i in range(250):
515-
w, b, c = time_path(T) # Generate new time path
516+
w, b, c = time_path(T, rng) # Generate new time path
516517
rcolor = random.choice(('c', 'g', 'b', 'k'))
517518
ax.plot(c, color=rcolor, lw=0.8, alpha=0.7)
518519

0 commit comments

Comments
 (0)