Minecraft wiki entry for Target_selectors, associated text: In Java Edition: [limit=<value>,sort=(nearest|furthest|random|arbitrary)] — Limit the number of targets, and specify selection priority.
sort=nearest — Sort by increasing distance. (Default for @p)
sort=furthest — Sort by decreasing distance.
sort=random — Sort randomly. (Default for @r)
sort=arbitrary — Sort by time created. (Default for @e, @a)