From: Brian Candler Date: 2010-03-02T05:47:58+09:00 Subject: Re: Random integer within a range? Reiichi Tyrael wrote: > It's work! Thank you David! > But there is no way to do it like in my version "rand(n1..n2)"? It's > more friendly that way XD Sure: def myrand(r=nil) if r.is_a?(Range) rand(r.last - r.first + (r.exclude_end? ? 0 : 1)) + r.first else rand(r) end end Or if you prefer: module Kernel alias :orig_rand :rand def rand(r=nil) if r.is_a?(Range) orig_rand(r.last - r.first + (r.exclude_end? ? 0 : 1)) + r.first else orig_rand(r) end end end I suspect it's not implemented in Ruby because it's not obvious what rand(0.3..5.7) should do. -- Posted via http://www.ruby-forum.com/.