We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 00e3b92 + 6c08a30 commit 71ed4cbCopy full SHA for 71ed4cb
Scripts/random.py
@@ -0,0 +1,26 @@
1
+# Python code for 1-D random walk.
2
+import random
3
+import numpy as np
4
+import matplotlib.pyplot as plt
5
+
6
7
+prob = [0.05, 0.95]
8
9
10
+start = 2
11
+positions = [start]
12
13
14
+rr = np.random.random(1000)
15
+downp = rr < prob[0]
16
+upp = rr > prob[1]
17
18
19
+for idownp, iupp in zip(downp, upp):
20
+ down = idownp and positions[-1] > 1
21
+ up = iupp and positions[-1] < 4
22
+ positions.append(positions[-1] - down + up)
23
24
25
+plt.plot(positions)
26
+plt.show()
0 commit comments