diff --git a/src/core/Cool-num.pm b/src/core/Cool-num.pm index 2f1229eb602..2f0f5bf5edb 100644 --- a/src/core/Cool-num.pm +++ b/src/core/Cool-num.pm @@ -67,8 +67,8 @@ augment class Cool { ~(pir::chr__SI(self)) } - our Num method rand() { - pir::box__PN(pir::rand__NN(self)) + method rand($x:) { + (+$x).rand; } method sin($x: $base = Radians) { @@ -312,8 +312,8 @@ proto chr($graph) { $graph.chr; } -sub srand(Int $seed = time) { - pir::srand__0I($seed); +proto sub srand($seed) { + srand(+$seed); } # vim: ft=perl6 diff --git a/src/core/Num.pm b/src/core/Num.pm index 24584d57a18..6209064abce 100644 --- a/src/core/Num.pm +++ b/src/core/Num.pm @@ -75,6 +75,10 @@ augment class Num does Real { } } + method rand(Num $x:) { + pir::box__PN(pir::rand__NN($x)) + } + method sin(Num $x: $base = Radians) { pir::sin__Nn($x.to-radians($base)); } diff --git a/src/core/Real.pm b/src/core/Real.pm index 3ac3c421b8e..c98737fb2dd 100644 --- a/src/core/Real.pm +++ b/src/core/Real.pm @@ -96,6 +96,10 @@ role Real does Numeric { $mag * $angle.sin(Radians)); } + method rand($x:) { + $x.Bridge.rand; + } + method sin(Real $x: $base = Radians) { $x.Bridge.sin($base); } @@ -264,3 +268,7 @@ multi sub infix:<**>(Real $a, Real $b) { our multi sub infix:(Real $a, Real $b) { $a - ($a div $b) * $b; } + +multi sub srand(Real $seed = time) { + pir::srand__0I($seed.Int); +}