Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix Range.{roll,pick}

  • Loading branch information...
commit 2fd18f4b66a69f2b9c925f1fbe720bfcf277faad 1 parent 0deac24
@moritz moritz authored
Showing with 9 additions and 8 deletions.
  1. +9 −8 src/core/Range.pm
View
17 src/core/Range.pm
@@ -132,13 +132,14 @@ class Range is Iterable does Positional {
gather loop { take self.roll }
}
multi method roll(Range:D:) {
- nextsame unless $!min.^isa(Int) && $!max.^isa(Int);
+ return self.list.roll unless $!min.^isa(Int) && $!max.^isa(Int);
my Int:D $least = $!excludes_min ?? $!min + 1 !! $!min;
- my Int:D $elems = 1 + ($!excludes_max ?? $!max - 1 !! $!max);
+ my Int:D $elems = 1 + ($!excludes_max ?? $!max - 1 !! $!max) - $least;
$elems ?? ($least + $elems.rand.floor) !! Any;
}
- multi method roll($num as Int) {
- nextsame unless $!min.^isa(Int) && $!max.^isa(Int);
+ multi method roll(Cool $num as Int) {
+ say $!min.WHAT, ' ', $!max.WHAT;
@kboga
kboga added a note

A debugging statement snuck in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return self.list.roll($num) unless $!min.^isa(Int) && $!max.^isa(Int);
return self.roll if $num == 1;
my int $n = nqp::unbox_i($num);
gather loop (my int $i = 0; $i < $n; $i = $i + 1) {
@@ -149,11 +150,11 @@ class Range is Iterable does Positional {
proto method pick(|$) { * }
multi method pick() { self.roll };
multi method pick(Whatever) { self.list.pick };
- multi method pick($n as Int) {
- nextsame unless $!min.^isa(Int) && $!max.^isa(Int);
+ multi method pick(Cool $n as Int) {
+ return self.list.pick($n) unless $!min.^isa(Int) && $!max.^isa(Int);
my Int:D $least = $!excludes_min ?? $!min + 1 !! $!min;
- my Int:D $elems = 1 + ($!excludes_max ?? $!max - 1 !! $!max);
- nextsame unless $elems > 3 * $n;
+ my Int:D $elems = 1 + ($!excludes_max ?? $!max - 1 !! $!max) - $least;
+ return self.list.pick($n) unless $elems > 3 * $n;
my %seen;
my int $i_n = nqp::unbox_i($n);
gather while $i_n > 0 {
Please sign in to comment.
Something went wrong with that request. Please try again.