There is a minor problem: the program should print another random number before restarting the loop.
There is a very annoying problem: see Talk:Pick random element, where there is an identical fundamental mistake in the C program. While neither of the tasks states explicitly that the distribution has to be uniform, it seems to me that it's implicit in the question.
The solutions given for several other languages use a bad method to generate the random numbers. I understand that for this task it's not fundamental, but then at least it should be stated somewhere that the method is poor.