A random-walk simulation program was developed to study the effect of dephasing spins in a uniform magnetic-field gradient in a porous material. It is shown that this simulation program correctly reproduces basic nuclear magnetic resonance behavior, such as the formation of a spin echo. The spin-echo decay due to dephasing in a nonrestricted medium gives the well-known exponential relation containing the cube of time, whereas the spin-echo decay due to dephasing in a porous material gives a monoexponential decay. By varying the pore size and magnetic-field gradient, the motional averaging regime and the localization regime can be simulated. Moreover, the unknown intermediate regime is investigated. By choosing the right scaling parameters, the spin-echo decay due to dephasing in a pore can be described by one master curve for all pore sizes and gradient strengths. This master curve reveals a small intermediate regime, perfectly symmetrical around the gradient for which the dephasing length is exactly equal to the structural length of the pore.