Module: Knj::Rand

Defined in:
lib/knj/rand.rb

Overview

This module is used to handel various random handeling.

Class Method Summary collapse

Class Method Details

.array(arr) ⇒ Object

Returns a random element in the given array.



9
10
11
12
# File 'lib/knj/rand.rb', line 9

def self.array(arr)
  key = rand(arr.length)
  return arr[key]
end

.range(first, last) ⇒ Object

Returns a random integer between the two integers given.



4
5
6
# File 'lib/knj/rand.rb', line 4

def self.range(first, last)
  return first.to_i + rand(last.to_i - first.to_i)
end