Commit c13f520
Replace direct np.random.* calls with np.random.RandomState instances (#8798)
### Description
Replace direct `np.random.*` global function calls with proper
`np.random.RandomState` instances for reproducibility, as requested in
#6888.
### Changes
| File | Call sites | Fix |
|------|-----------|-----|
| `monai/transforms/utils.py` | 3 × `np.random.random.__self__` | →
`np.random.RandomState()` |
| `monai/transforms/signal/array.py` | 2 × `np.random.choice` | →
`self.R.choice` (classes already Randomizable) |
| `monai/data/synthetic.py` | 2 × `np.random.random.__self__` | →
`np.random.RandomState()` |
| `monai/data/utils.py` | 1 × `np.random.randint` fallback | →
`np.random.RandomState().randint` |
| `monai/utils/ordering.py` | 1 × `np.random.shuffle` | →
`np.random.RandomState().shuffle` |
### Scope
This PR covers 9 functional call sites across 5 files. The remaining
`np.random.*` calls in the codebase are either:
- **Docstring examples** (auto3dseg, visualize) — educational, not
functional
- **`np.random.seed` in `set_determinism()`** — intentionally sets
global state
- **apps/deepedit/ and apps/nuclick/** — would require adding
`Randomizable` inheritance, left for a follow-up
### Checks
- [x] `Signed-off-by` included (DCO)
- [x] No new global random state usage introduced
- [x] Signal transforms use existing `self.R` from `Randomizable` base
class
Ref #6888
---------
Signed-off-by: SexyERIC0723 <haoyuwang144@gmail.com>
Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com>1 parent 827a4a7 commit c13f520
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
| 276 | + | |
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
357 | | - | |
| 357 | + | |
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| |||
0 commit comments