Random walk around a central location in a limited area?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
A random walk is a mathematical formalization of a path that consists of a succession of random steps. This concept finds extensive application in various fields such as physics, economics, biology, and computer science. This article will explore the concept of a random "walk" around a central location within a confined or limited area.
Overview of Random Walks
A random walk is a sequence of random steps on some mathematical space. The simplest random walk is a one-dimensional walk where at each step, the walker can go either forward or backward with equal probability. In a two-dimensional space, each step can lead the walker to either of the four cardinal directions: north, south, east, or west.
Mathematical Representation
The random walk can be mathematically represented as follows:
For a one-dimensional random walk:
Where:
• is the position at step .
• is a random variable that can take $+1$ or $ -1 $ with probability .
For a two-dimensional walk, it can be represented as:
Where:
• $Z_\{n\}^\{x\}$ and $Z_\{n\}^\{y\}$ are independent random variables that represent the step in the X and Y direction, respectively.
Random Walk within a Confined Area
When considering a random walk in a confined area centered around a specific location, the complexity increases. The most common constraints involve ensuring that the walk stays within the boundary, which can be circular, square, or any arbitrary shape.
Circular Boundary
For circular boundaries: • Ensure that the distance from the central point does not exceed the radius of the circle. • Use polar coordinates to simplify calculations, especially when dealing with angles.
Square Boundary
In a square or rectangular boundary: • Reflect the particle back into the area if it tries to step outside. • If the walker reaches a boundary edge, one can either: • Reflect the walk. • Wrap around to the opposite edge.
Numerical Example
Consider a square area centered at the origin with boundaries at and on both X and Y axes. Assume a two-dimensional random walk starting from the origin.
• If the next step is outside for either X or Y, the step is adjusted or reversed to stay within the limits.
Key Iterations Over 10 Steps:
| Step | X Position | Y Position | Action |
| 1 | -1 | 1 | Accepted |
| 2 | 0 | 0 | Accepted |
| 3 | -11 | 0 | Reflected |
| 4 | -9 | 1 | Accepted |
| 5 | -8 | 2 | Accepted |
| 6 | 10 | 3 | Reflected |
| 7 | 8 | 3 | Accepted |
| 8 | 9 | 4 | Accepted |
| 9 | 10 | 5 | Reflected |
| 10 | 9 | 6 | Accepted |
Applications and Utility
Random walks around a central location are used to model numerous phenomena: • Ecological Studies: Tracking animal movement in a confined habitat. • Physics: Modeling diffusion processes constrained within materials. • Computer Science: Generating realistic pathfinding in video games or simulations.
Monte Carlo Simulations
Random walks are pivotal in Monte Carlo simulations for estimating integrals and solving systems with a large number of degrees of freedom, such as in statistical mechanics.
Conclusion
Random walks around a central location in a limited area not only present interesting mathematical challenges but also have a rich array of applications across multiple fields. By adjusting for constraints such as boundaries, the utility of random walks can be extended to model real-world phenomena more accurately and inform decision-making processes in diverse domains.
Related reading

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.