Skip to content

Commit 6c08a30

Browse files
authored
Create random.py
1 parent 8baadf4 commit 6c08a30

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy