Changed for-loop with a while-loop. So there is no chance that strange characters will appear in the random numbers.