Skip to content

Commit 71ed4cb

Browse files
authored
Merge pull request powerexploit#46 from umarbrowser/master
Create random.py
2 parents 00e3b92 + 6c08a30 commit 71ed4cb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Scripts/random.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)