-
-
Notifications
You must be signed in to change notification settings - Fork 80
Description
pg/macros/contexts/contextInteger.pl
Line 151 in 0c7f42d
| $self->Error("Start or range must be before end of range") if $index > $end; |
pg/macros/contexts/contextInteger.pl
Line 159 in 0c7f42d
| while ($index < $end) { |
I suggest changing the less than into less than or equal to in the while condition in line 159. The strict less than prevents the list of primes generated from including the $end. This means randomPrime(3,11), for example, cannot return 11. This seems counterintuitive given the behavior of random(3,11).
Alternatively, changing the condition in line 151 to include the equality would make the error message more useful. (Although also note the typo "or" in line 151).
pg/macros/contexts/contextInteger.pl
Lines 238 to 239 in 0c7f42d
| $self->Error("Could not find any prime numbers in range.") if $#primes == 0; | |
| my $primeIndex = $main::PG_random_generator->random(0, ($#primes - 1), 1); |
In line 238, I believe the 0 was meant to be -1. If there were no primes in the range, then _getPrimesInRange would return an empty array with the final index negative one.
In line 239, ($#primes - 1) should be $#primes. As is, the code prevents the largest prime in the range from ever being selected.
Perhaps the intent was for randomPrime(a,b) to return a prime in [a,b). Although, again, that seems counterintuitive. But, in any case, as things stand, neither b nor the greatest prime less than b can result from randomPrime. For example, randomPrime(2,5) is always 2.
Thanks,
Dan