added randomness on breadth-first search