Generate a Random MAC Address in Python
Tuesday, September 29th, 2009
If you’d like to learn more about programming, contact me for a one-on-one lesson.
1 2 3 4 5 6 7 8 9 10 | import random def randomMacAddress(): """Returns a completely random Mac Address""" mac = [0x00, 0x16, 0x3e, random.randint(0x00, 0x7f), \ random.randint(0x00, 0xff), random.randint(0x00, 0xff)] return ':'.join(map(lambda x: "%02x" % x, mac)) if __name__ == '__main__': print randomMacAddress() |
I find
map(lambda...hard to read.I prefer ':'.join('%02x' % x for x in mac)
/useless critique
Interesting… I've always been a bit partial to map i suppose :)
The backslash is not necessary. The space after the opening bracket goes against the style recommendations of PEP-8 and is inconsistent with the lack of a space in front of the closing bracket.
Some people would prefer ':'.join('%02x' % x for x in mac) instead of map + lambda.
BTW an interesting commenting interface. You're encouraged to type your comment before reading what others already posted — in fact, due to the size of my screen, I didn't even notice there were already some comments.
I have the option to put the comment box at both the top and the bottom. sometimes the comments get rather large, and rather than pagination, i prefer them all to be listed on the page. When this is the case, for usability (everyone just wants to put in their two cents) I like to keep it up top. :)
The backslash is there for the sole purpose of keeping the code a certain width for my aesthetics :)
Thanks for the braket+space comment. I'll fix that.
The backslash is not necessary. The space after the opening bracket goes against the style recommendations of PEP-8 and is inconsistent with the lack of a space in front of the closing bracket.
Some people would prefer ':'.join('%02x' % x for x in mac) instead of map + lambda.
BTW an interesting commenting interface. You're encouraged to type your comment before reading what others already posted — in fact, due to the size of my screen, I didn't even notice there were already some comments.
I have the option to put the comment box at both the top and the bottom. sometimes the comments get rather large, and rather than pagination, i prefer them all to be listed on the page. When this is the case, for usability (everyone just wants to put in their two cents) I like to keep it up top. :)
The backslash is there for the sole purpose of keeping the code a certain width for my aesthetics :)
Thanks for the braket+space comment. I'll fix that.
<script type=”text/javascript” charset=”utf-8″>
</script>
<ul id=”mylist”>
<li class=”listitems”>
my name is
</li>
<li class=”listitems”>
billy joe
</li>
<li class=”listitems”>
i'm an idiot
</li>
</ul>