Skip to content

Instantly share code, notes, and snippets.

@masak
Created October 14, 2011 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masak/1288000 to your computer and use it in GitHub Desktop.
Save masak/1288000 to your computer and use it in GitHub Desktop.
[PATCH] add .roll
From fbae4b80420e971b3562a982baca4416b453bee0 Mon Sep 17 00:00:00 2001
From: Carl Masak <cmasak@gmail.com>
Date: Fri, 14 Oct 2011 21:01:32 +0200
Subject: [PATCH] add .roll
---
lib/CORE.setting | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/lib/CORE.setting b/lib/CORE.setting
index 9309fd1..2318ab6 100644
--- a/lib/CORE.setting
+++ b/lib/CORE.setting
@@ -135,6 +135,11 @@ my class Any is Mu {
method hash() { anon %hash = @(self) }
+ multi method roll($num = 1) {
+ return self[floor(self.elems.rand)] if $num == 1;
+ return map { self[floor(self.elems.rand)] }, ^$num;
+ }
+
multi method pick($num is copy = 1) {
my @l = @(self);
--
1.7.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment