my $interval = 60*60; # one hour my $random = int(time/$interval)%$n; # not random, though