Created
August 27, 2015 21:48
-
-
Save glickbot/c9912af423aa62ffee7d to your computer and use it in GitHub Desktop.
Erlang Integer to Mac String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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