in reply to Don't-Repeat-Myself code for improvement

how about just filter out the recent ids with grep before doing the rand(), e.g.
# ... my @not_recent = grep !defined( $recent_ids{ $_ } ), @ids; my $idno; { use integer; $idno = (1+$#not_recent) * rand(); } # ...
or alternatively, sort the items by $somehash ||= -M item into the array and just shift off the first three before doing the rand().

-M

Free your mind