lib/rfauxfactory.rb
# Generates a random MAC address.
Generates a random MAC address.
Generates a random MAC address .
def gen_mac(delimiter: ':', multicast: nil, locally: nil)
      raise ArgumentError, "#{delimiter} is not valid delimiter" unless %w[: -].include?(delimiter)
      multicast = gen_boolean if multicast.nil?
      locally = gen_boolean if locally.nil?
      first_octet = rand(0..255)
      multicast ? first_octet |= 0b00000001 : first_octet &= 0b11111110
      locally ? first_octet |= 0b00000010 : first_octet &= 0b11111101
      octets = [first_octet]
      octets += (Array.new(5) { rand(0..255) })
      octets.map { |octet| format('%02x', octet) }.join(delimiter)
    end
def gen_mac ( delimiter : ':' , multicast : nil , locally : nil ) raise ArgumentError , "#{delimiter} is not valid delimiter" unless %w[ : - ] . include? ( delimiter ) multicast = gen_boolean if multicast . nil? locally = gen_boolean if locally . nil? first_octet = rand ( 0 .. 255 ) multicast ? first_octet |= 0b00000001 : first_octet &= 0b11111110 locally ? first_octet |= 0b00000010 : first_octet &= 0b11111101 octets = [ first_octet ] octets += ( Array . new ( 5 ) { rand ( 0 .. 255 ) } ) octets . map { | octet | format ( '%02x' , octet ) } . join ( delimiter ) end
Generates a random MAC address.
Generates a random MAC address .
delimiter
multicast
locally