Also, if this is just using 3 random hosts, there's no point using (i to (i+2)).. you can use (1 to 3) or just Array.fill(3)(machines(rnd.nextInt(machines.size))