artistmy $hash = { 1 => 0.2, 2 => 0.3, 3 => 0.5 }; my $sum; my $hash2; while(my($key,$value) = each %{$hash}){ $sum += $value; print "$sum . $key\n"; $hash2->{$sum} = $key; } foreach (1..10){ my $x = rand(1); print "$x\t"; foreach (sort { $a <=> $b } keys %{$hash2}){ if($x < $_){ print $hash2->{$_},"\n"; last; } } }
In reply to Re: Drawing samples from a set
by artist
in thread Drawing samples from a set
by crenz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |