J
Jacob JKW
If this has already been asked and answered somewhere before, I can't
find where.
Let's say I have a sorted array of real numbers between 0 and 1. What
do you think would be the fastest way of determining between which two
indexes a randomly generated number lay?
Specifically, what would be a faster way to do this:
#!perl
my $cmf_ra = [0, 0.25, 0.33, 0.625, 0.9, 0.95];
my $rand = rand();
foreach my $i (0 .. $#$cmf_ra) {
(print $i and last) if $rand <= $cmf_ra->[$i];
}
Thanks,
Jacob
find where.
Let's say I have a sorted array of real numbers between 0 and 1. What
do you think would be the fastest way of determining between which two
indexes a randomly generated number lay?
Specifically, what would be a faster way to do this:
#!perl
my $cmf_ra = [0, 0.25, 0.33, 0.625, 0.9, 0.95];
my $rand = rand();
foreach my $i (0 .. $#$cmf_ra) {
(print $i and last) if $rand <= $cmf_ra->[$i];
}
Thanks,
Jacob