Sorting and looped random calculations