Can be useful in generating fake MAC addresses while writing specs for a class which has a MAC address attribute.
FactoryGirl.define do
sequence :mac do |n|
12.times.map { num = (0..15).to_a.sample; num.to_s(16) }.each_slice(2).to_a.map { |arr| arr.join('') }.join(":").upcase
end
end
Sample Output
90:A2:EE:23:BC:EA
Instead of generating a nibble at a time and have to deal with combining the nibbles into a byte, how about generating the entire byte?