my $max; chomp($max = ) while(not defined $max && $max =~ m/^[0-9]+$/); my $answer = int(rand($max))+1;