devi modificare questo:

_x = random(500);

che sta nel ciclo for del duplicate.