Enough boring theory. Let`s take a break to get some coding knowledge. So, to code the random walk, we basically need some libraries in python, some for math and some others for curve fitting.
Required Libraries
pip install matplotlib
This would be enough to get you through the installation.
pip install numpy
Onedimensional random walk . An elementary example of a random walk is a random walk over a string of integers, which starts at 0 and is shifted by +1 or? 1 with equal probability.
So let`s try to implement 1D random walk in python.
Output:
Higher dimensions In higher dimensions, many randomly passed points have interesting geometric properties. In fact, a discrete fractal is obtained, that is, a set that demonstrates stochastic selfsimilarity on a large scale. On a small scale, you can observe "irregularities" arising from the net on which the walk is performed. Lawler`s two books mentioned below are good sources on this topic. The trajectory of a random walk — it is a set of visited points, treated as a set that does not account for when the walk has reached a point. In one dimension, the trajectory — it`s just all the points between the minimum height and the maximum height that the walk has reached (on average, both orders of magnitude? N).
Let`s try to create a random walk in 2D.


Output:
Applications
Links
1. Wikipedia — A random walk
2. Stackoverflow — Random Walk 1D
3. matplotlib documentation
This article is courtesy of Subhajit Saha . If you are as Python.Engineering and would like to contribute, you can also write an article using contribute.python.engineering or by posting an article contribute @ python.engineering. See my article appearing on the Python.Engineering homepage and help other geeks.
Please post comments if you find anything wrong or if you`d like to share more information on the topic discussed above.