Omniadisce

Computational physics 18.1: A drunkard's walk

Lesson Beginner

Join free to take this lesson

Anyone can look around, but taking a lesson needs a free account. With one, your answers are checked step by step and your progress is saved, so you can stop and pick up where you left off on any device.

12 steps ยท about 25 min

By the end you can

  • Say what a random walk is
  • Take one random step with rng.choice([-1, 1]), and many in a loop
  • Make all the steps at once with size=N, and find where the walker ends with np.sum
  • Find the whole path with np.cumsum, a running total

Who it is for: Anyone who has done lesson 9.2 (random numbers with a seed) and unit 17 (Monte Carlo).

The steps

  1. The drunkard's walk
  2. A coin toss in Python
  3. Ten steps
  4. Where can he be?
  5. Steps of a metre
  6. Many nights
  7. All the steps at once
  8. Where he ends
  9. The whole path: np.cumsum
  10. A running total
  11. The farthest he strayed
  12. One walk

Discussion 0 comments

Log in to join the discussion.

× Enlarged view