Skip to content

[os_egm.md] Update np.random → Generator API#996

Open
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-os-egm
Open

[os_egm.md] Update np.random → Generator API#996
Chihiro2000GitHub wants to merge 1 commit into
mainfrom
update-rng-os-egm

Conversation

@Chihiro2000GitHub

@Chihiro2000GitHub Chihiro2000GitHub commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

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

The seeded np.random.seed(...) / np.random.randn(...) pattern in create_model is replaced with an explicit seeded generator rng = np.random.default_rng(seed).

Related PRs and issues

I checked for open PRs and issues related to this lecture. No open PR touches it and no open issue concerns it — nothing overlaps with this migration.

Details

  • In create_model, np.random.seed(seed) + np.random.randn(shock_size)rng = np.random.default_rng(seed) + rng.standard_normal(shock_size).
  • The existing fixed seed (1234) is kept, since the lecture already seeded for reproducibility. rng is local to create_model, so no hidden global random state remains.
  • The lecture has no @jit/prange code. (This is the NumPy version; the JAX version lives in os_egm_jax.)

Note for reviewers

default_rng produces a different stream from the legacy RandomState, so the same seed gives different draws. The figures are unchanged; only the printed numbers shift slightly.

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

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rs2tDEcDXLnfMnM88v8e1D
@github-actions

Copy link
Copy Markdown

📖 Netlify Preview Ready!

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

Commit: 326096a

📚 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