1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
From: =?utf-8?q?Timo_R=C3=B6hling?= <roehling@debian.org>
Date: Fri, 10 Oct 2025 12:41:02 +0200
Subject: Make random numbers in documentation reproducible
---
doc/source/conf.py | 5 +++++
doc/source/reference/random/new-or-different.rst | 19 -------------------
2 files changed, 5 insertions(+), 19 deletions(-)
diff --git a/doc/source/conf.py b/doc/source/conf.py
index fa988ea..f02f9bb 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -628,3 +628,8 @@ try_examples_global_warning_text = (
" report them on the"
" [NumPy issue tracker](https://github.com/numpy/numpy/issues)."
)
+
+# Reseed numpy random generator for reproducible documentation
+numpy.random.seed(42)
+numpy.random.default_rng = lambda seed=None, actual_default_rng=numpy.random.default_rng: actual_default_rng(seed if seed is not None else 42)
+
diff --git a/doc/source/reference/random/new-or-different.rst b/doc/source/reference/random/new-or-different.rst
index 44cf7aa..581cd4e 100644
--- a/doc/source/reference/random/new-or-different.rst
+++ b/doc/source/reference/random/new-or-different.rst
@@ -44,25 +44,6 @@ Feature Older Equivalent Notes
`~.Generator.standard_gamma`. Because of the change in algorithms, it is not
possible to reproduce the exact random values using `Generator` for these
distributions or any distribution method that relies on them.
-
-.. ipython:: python
-
- import numpy.random
- rng = np.random.default_rng()
- %timeit -n 1 rng.standard_normal(100000)
- %timeit -n 1 numpy.random.standard_normal(100000)
-
-.. ipython:: python
-
- %timeit -n 1 rng.standard_exponential(100000)
- %timeit -n 1 numpy.random.standard_exponential(100000)
-
-.. ipython:: python
-
- %timeit -n 1 rng.standard_gamma(3.0, 100000)
- %timeit -n 1 numpy.random.standard_gamma(3.0, 100000)
-
-
* `~.Generator.integers` is now the canonical way to generate integer
random numbers from a discrete uniform distribution. This replaces both
`randint` and the deprecated `random_integers`.
|