in reply to Random number in while loop

Your problem is that you are not using the strictures:
use strict; use warnings;

This would have given you this type of warning message:

Argument isn't numeric in numeric eq (==)

which (might) have led you to using the string operator eq instead of ==.