Three key points:
Reservoir sampling gives uniform selection without preprocessing or knowing the count.
Each element gets replaced with probability where is its position among matches.
This technique works for streaming data where you cannot store all matches.