Skip to content

Instantly share code, notes, and snippets.

@glickbot
Created August 27, 2015 21:48
Show Gist options
  • Save glickbot/c9912af423aa62ffee7d to your computer and use it in GitHub Desktop.
Save glickbot/c9912af423aa62ffee7d to your computer and use it in GitHub Desktop.
Erlang Integer to Mac String
-module(mac_string_util).
-export([rand_mac/0, rand_mac/1, int_to_mac/1]).
rand_mac() ->
rand_mac(10000).
rand_mac(Int) ->
int_to_mac(random:uniform(Int)).
int_to_mac(Int) ->
MacStr = string:right(httpd_util:integer_to_hexlist(Int),12,$0),
OctetList = [ [X,Y] || <<X,Y>> <= erlang:list_to_binary(MacStr) ],
string:join(OctetList, "-").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment