Skip to content

[hansen_singleton_1983.md] Update np.random → Generator API#974

Open
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-hansen-singleton-1983
Open

[hansen_singleton_1983.md] Update np.random → Generator API#974
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-hansen-singleton-1983

Conversation

@Chihiro2000GitHub

Copy link
Copy Markdown
Contributor

Summary

This PR migrates legacy NumPy random API usage in hansen_singleton_1983.md as part of QuantEcon/meta#299.

The only legacy usage was inside simulate_restricted_var, which relied on the global random state via np.random.seed and np.random.multivariate_normal. This is now replaced with a local np.random.default_rng generator, consistent with the other simulation functions in the lecture (starting_values and simulate_multi_asset_nominal_returns) that already use the Generator API.

Details

  • Replaced if seed is not None: np.random.seed(seed) with a local rng = np.random.default_rng(seed).
  • Replaced np.random.multivariate_normal(...) with rng.multivariate_normal(...).
  • rng is defined locally inside simulate_restricted_var, so the function remains self-contained.
  • No fixed seed was newly introduced; the existing seed=0 default is preserved, so simulation output is unchanged.
  • No prose changes were needed, and there are no Numba (@jit/@njit/@jitclass/parallel/prange) cases in this file.

Note: np.random.default_rng(None) reproduces the original "do not seed" behaviour when seed is None, so the previous if seed is not None guard was dropped without changing semantics.

Hi @mmcky and @HumphreyYang, I'd be grateful if you could take a look when you have time.

@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-974--sunny-cactus-210e3e.netlify.app

Commit: 0ccf378

📚 Changed Lectures


Build Info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant