Algorithm for preventing repetition in random generated positions