Class: VoucherCode::Helpers::Randomize

Inherits:
Object
  • Object
show all
Defined in:
lib/voucher_code/helpers/randomize.rb

Class Method Summary collapse

Class Method Details

.random_element(array) ⇒ Object



9
10
11
# File 'lib/voucher_code/helpers/randomize.rb', line 9

def random_element(array)
  array[random_int(0, array.length - 1)]
end

.random_int(min, max) ⇒ Object



5
6
7
# File 'lib/voucher_code/helpers/randomize.rb', line 5

def random_int(min, max)
  (rand * (max - min + 1)).floor + min
end