How does syncthing choose a relay?

It checks the latency of relays and puts them in 50ms buckets, trying the lowest-latency ones first. Which relay is chosen within those buckets is random.