sub genPickerConverted { my %kmer_prob = %{ $_[0] }; my @vals = keys %kmer_prob; my @odds = (); foreach my $val (@vals) { push (@odds, $kmer_prob{$val}); } my @order = sort{ $odds[ $a ] <=> $odds[ $b ] } 0 .. $#odds; @odds = @odds[ @order ]; @vals = @vals[ @order ]; my $t = 0; $t += $_ for @odds; $_ /= $t for @odds; $odds[ $_ + 1 ] += $odds[ $_ ] for 0 .. $#odds - 1; return sub { my $r = rand(); $r < $odds[ $_ ] and return $vals[ $_ ] for 0 .. $#odds; }; }
In reply to Re^10: an algorithm to randomly pick items that are present at different frequencies
by efoss
in thread an algorithm to randomly pick items that are present at different frequencies
by efoss
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |