Sorting Sediments

One of the main things that we use for identifying clastic sedimentary rocks is grain size, the size of the pieces. Rocks that have been deposited by water or wind tend to be very well sorted, with all of the pieces being pretty much the same size. How does that happen?