I have a $9 \times 9$ square lattice. In each site of the lattice, there are $N$ molecules, where $N$ is a large random number and it is different for different sites. N equal to 100000000+-100 in beginning and changes by passing time. I want each molecule to do a random walk in each time step. $N$ is very large and it is not possible to apply random walk for each molecule in each site. Could anyone help? It is a part of other code, actually molecules f cites are consumed by other particles and they diffuse in time, but the part I have problem in is diffusion of molcules. I don't have enough score to answer the comments, so I answer here. Yes lattice is 2d. Yes, Exactly! I want number of particles in each site.But I don't underestand what do you mean. Could you provide an answer?
In the comments, @WolfgangBangert mentions the first part, the representation: instead of storing for $10^8$ particles a lattice location -- a two dimensional vector $(x,y)$ with 9 entries in each dimension -- you choose the dual representation by storing for each site $(x,y)$ the number of particles which occupy the site.
The second component is the transition. Straightforwardly, you would have to draw two times $10^8$ random numbers in order to check whether each one of the particles undergoes a transition. By this, however, you would have won nothing (regardless of the reduced representation of the system state in step one).
Therefore you approximate the distribution of the particles which undergo a transition by a normal distribution, which should be a very good approximation as your $N$ is quite large. The theoretical basis for this is the central limit theorem, and the parameters of the normal distribution depend on your microscopic transition law. You then draw a few random numbers from the normal -- which might even not be necessary as the normal should be really sharp, so it's possible you can just pick the mean.
Note that the above procedure is similar to what is done in classical statistical physics, when going from the microscopic description to the canonical ensemble.
For such large numbers the diffusion process becomes essentially 'deterministic' (https://en.wikipedia.org/wiki/Law_of_large_numbers) so the classic approach is to implement a finite differencing method for a diffusion equation, such as: https://nl.mathworks.com/matlabcentral/fileexchange/38088-diffusion-in-1d-and-2d .