module FFaker::PhoneNumber
def imei(serial_number = nil)
def imei(serial_number = nil) # IMEI Format: # AA-BBBBBB-CCCCCC-D characters = Array.new(15, 0) rbi_codes = %w[01 10 30 33 35 44 45 49 50 51 52 53 54 86 91 98 99] serial_number ||= rand(0...1_000_000) serial_number = format('%06d', serial_number).chars.map(&:to_i) first_two_chars = fetch_sample(rbi_codes) characters[0, 2] = first_two_chars.chars.map(&:to_i) # serial number part 2.upto(7) do |current_position| characters[current_position] = fetch_sample((0..9).to_a) end 8.upto(13) do |current_position| characters[current_position] = serial_number[current_position - 8] end current_checksum = characters.reverse.each_with_index.inject(0) do |sum, (digit, i)| digit *= 2 if i.odd? digit -= 9 if digit > 9 sum + digit end final_digit = (10 - (current_checksum % 10)) % 10 characters[14] = final_digit characters.join end