We propose a new method which highlights the efficiency of stochastic models in solving self-organization problems. Our method, which is based on a comparison between the local and general past states of the system, does not require any hierarchical decision maker or communication between the individuals. The environment is a rectangular lattice with a number of objects which have to be sorted by some random walk robots. We present theoretical arguments and experimental simulations in support of the idea that our new algorithm represents a powerful tool in studying collective sorting.