From b455c0242fcdcbe2a4f51f61afd315757963da02 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 9 Apr 2007 21:17:05 +0000 Subject: [PATCH] extends: pick_one and rand methods for Range --- lib/rbot/core/utils/extends.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/rbot/core/utils/extends.rb b/lib/rbot/core/utils/extends.rb index a749f92a..bcea735b 100644 --- a/lib/rbot/core/utils/extends.rb +++ b/lib/rbot/core/utils/extends.rb @@ -27,6 +27,20 @@ class ::Array end end +# Extensions to the Range class +# +class ::Range + + # This method returns a random number between the lower and upper bound + # + def pick_one + len = self.last - self.first + len += 1 unless self.exclude_end? + self.first + Kernel::rand(len) + end + alias :rand :pick_one +end + # Extensions for the Numeric classes # class ::Numeric -- 2.39.2