SUMMARYWe present a lattice Boltzmann-BGK (LBGK) algorithm for a diffusion equation together with a Robin boundary condition, which we apply in the case of nuclear magnetic resonance relaxation. The boundary condition we employ is independent of the direction of the wall. This makes the algorithm very suitable for complicated geometries, such as porous media. We discuss the effect of lattice topology by using, respectively, an eight-speed and a four-speed lattice. The numerical algorithm is compared with analytical results for a square and an equilateral triangle. The eight-speed lattice performs well in both cases. The four-speed lattice performs well for the square, but fails in the case of an equilateral triangle. Comparison with a random walk algorithm is also included. The LBGK algorithm presented here can also be used for a convective diffusion problem if the speed of the fluid can be neglected close to the boundary.