sub qshuf { my %hash; sort { ($hash{$a}||=rand 1) <=> ($hash{$b}||=rand 1) } @_; } #### for (1 .. 10) { print qshuf(qw/a b c D D D D/), $/; }