So your function looks at the particles that are seated on the bottom and asks if they can slide on the sides, and then affects this movement if they can.
Do you have this in a loop? If so, you can consider particles from the bottom up, while sliding motion can take place at any point on the pile. You can try to shuffle the particle list before the loop or re-select random items from the list until you get a low level of resolution.
In the case of a 2D array, you can try to cycle from different directions or find other ways to mix it - again, randomly selecting pixels may be the wrong choice. Simulated annealing comes to mind.
Or you can add a random check to the rolling state. Particles should be semi-stable in their original positions, so perhaps there is only a 50% chance of them sliding down.
Hope this helps!
source share