Can I rely on random map iteration to implement random pairing of clients in a web application? I tried looking around, but I can't seem to find a breakdown of how random this accident is.
The algorithm will look something like this:
var clients map[Client]struct{}
func PairClient(c Client) (Client, error) {
for m := range clients {
if m != c {
return m, nil
}
}
return nil, fmt.Errorf("lobby: insufficient number of clients")
}
Will it be enough if there are> 1000 connected clients, or should I support a separate piece of clients and arbitrarily choose from this?
source
share