-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRandom_Walk.py
38 lines (32 loc) · 884 Bytes
/
Random_Walk.py
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
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(123)
all_walks = []
for i in range(500):
random_walk = [0]
for x in range(100):
step = random_walk[-1]
dice = np.random.randint(1, 7)
if dice <= 2:
step = max(0, step - 1)
elif dice <= 5:
step = step + 1
else:
step = step + np.random.randint(1, 7)
if np.random.rand() <= 0.001:
step = 0
random_walk.append(step)
all_walks.append(random_walk)
np_aw = np.array(all_walks)
np_aw_t = np.transpose(np_aw)
ends = np_aw_t[-1]
plt.plot(np_aw_t)
plt.show()
plt.hist(ends)
plt.show()
gr_sixty = []
for i in ends:
if i >= 60:
gr_sixty.append(i)
print("I have " + str(len(gr_sixty) / len(ends)*100) + " % of chance to reach the floor 60 in Empire State Building" )