Return a random element from the range.
(1..4).at_rand #=> 2 (1..4).at_rand #=> 4 (1.5..2.5).at_rand #=> 2.06309842754533 (1.5..2.5).at_rand #=> 1.74976944931541 ('a'..'z').at_rand #=> 'q' ('a'..'z').at_rand #=> 'f'
CREDIT: Lavir the Whiolet
# File lib/more/facets/random.rb, line 119 119: def at_rand 120: if first.respond_to?(:succ) 121: to_a.at_rand 122: elsif Numeric===first && Numeric===last 123: number = (last - first) * Random.number + first 124: (number == last && exclude_end?) ? first : number 125: else 126: nil 127: end 128: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.