summaryrefslogtreecommitdiff
path: root/prob/random_walk_1d.py
diff options
context:
space:
mode:
Diffstat (limited to 'prob/random_walk_1d.py')
-rw-r--r--prob/random_walk_1d.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/prob/random_walk_1d.py b/prob/random_walk_1d.py
new file mode 100644
index 0000000..445db06
--- /dev/null
+++ b/prob/random_walk_1d.py
@@ -0,0 +1,22 @@
+
+import random
+import matplotlib.pyplot as plt
+from collections import Counter
+import pandas as pd
+
+
+def random_walk(N):
+ x = 0
+ for i in range(N):
+ dx = random.choice([1, -1])
+ x += dx
+ return x
+
+
+if __name__ == '__main__':
+ n_samples = 50000
+ final_x = []
+ for i in range(n_samples):
+ final_x.append(random_walk(100))
+ pd.Series(final_x).value_counts().sort_index().plot(kind='bar')
+ plt.show()