**Exercise 10.3: Brownian motion**

Brownian motion is the motion of a particle, such as a smoke or dust particle, in a gas, as it is buffeted by random collisions with gas molecules. Make a simple computer simulation of such a particle in two dimensions as follows. The particle is confined to a square grid or lattice L × L squares on a side, so that its position can be represented by two integers i, j = 0 . . . L − 1. It starts in the middle of the grid. On each step of the simulation, choose a random direction—up, down, left, or right—and move the particle one step in that direction. This process is called a random walk. The particle is not allowed to move outside the limits of the lattice—if it tries to do so, choose a new random direction to move in.

Write a program to perform a million steps of this process on a lattice with L = 101 and make an animation on the screen of the position of the particle. (We choose an odd length for the side of the square so that there is one lattice site exactly in the center.)

**Exercise 10.8: Calculate a value for the integral**

,

using the importance sampling formula, Eq. (10.42), with w(x) = x^{−1/2}, as follows.

a) Show that the probability distribution p(x) from which the sample points should be drawn is given by

and derive a transformation formula for generating random numbers between zero and one from this distribution.

b) Using your formula, sample N = 1,000,000 random points and hence evaluate the integral. You should get a value around 0.84.