Skip to content

Commit f0d4080

Browse files
committed
Use a RandomState instance with a fixed seed
1 parent 063bccf commit f0d4080

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/pylab_examples/psd_demo_complex.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import matplotlib.pyplot as plt
1212
import matplotlib.mlab as mlab
1313

14+
prng = np.random.RandomState(123456) # to ensure reproducibility
15+
1416
fs = 1000
1517
t = np.linspace(0, 0.3, 301)
1618
A = np.array([2, 8]).reshape(-1, 1)
1719
f = np.array([150, 140]).reshape(-1, 1)
18-
xn = (A * np.exp(2j * np.pi * f * t)).sum(axis=0) + 5 * np.random.randn(*t.shape)
20+
xn = (A * np.exp(2j * np.pi * f * t)).sum(axis=0) + 5 * prng.randn(*t.shape)
1921

2022
fig, (ax0, ax1) = plt.subplots(ncols=2)
2123

0 commit comments

Comments
 (0)