Skip to content

Commit be8e253

Browse files
committed
Use a RandomState instance with a fixed seed
1 parent 382b319 commit be8e253

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/pylab_examples/psd_demo3.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import matplotlib.pyplot as plt
99
import matplotlib.mlab as mlab
1010

11+
prng = np.random.RandomState(123456) # to ensure reproducibility
12+
1113
fs = 1000
1214
t = np.linspace(0, 0.3, 301)
1315
A = np.array([2, 8]).reshape(-1, 1)
1416
f = np.array([150, 140]).reshape(-1, 1)
15-
xn = (A * np.sin(2 * np.pi * f * t)).sum(axis=0) + 5 * np.random.randn(*t.shape)
17+
xn = (A * np.sin(2 * np.pi * f * t)).sum(axis=0) + 5 * prng.randn(*t.shape)
1618

1719
fig, (ax0, ax1) = plt.subplots(ncols=2)
1820

0 commit comments

Comments
 (0)