Minecraft wiki entry for Target_selectors, associated text: Examples in Java Edition:
@a[limit=3,sort=nearest] or @p[limit=3] — Select the nearest three players.
@a[limit=4,sort=furthest] — Select the furthest four players.
@a[limit=2,sort=random] or @r[limit=2] — Select two players, chosen randomly.