Thank you for your answer. The script I am currently using is fixed 0E: 11:22:33:44:55 at the first byte, with 0E at the beginning and random generation at the end. However, I think the range is still not large enough
Hi Rosa,
I don't know how you generate the MAC addresses but if you feel that the range is not enough, I suspect you are duplicating one character for every value, giving you the form
0e:zz:yy:xx:ww:vv. This will result in 10^5 different MAC addresses.
We can do better ...
For example we can generate random numbers between 00 and 99 for each of the 5 bytes. This will raise the number of produced values to 100^5, or 10 billions, more than the number of people alive on earth.
{
# Fixed prefix
:local macAddress "0e"
# Add the remaining 5 bytes
for byte from=0 to=4 do={
:local curByte ":"
# Generate two digits.
:set curByte ($curByte . [:tostr [:rndnum from=0 to=9] ] )
:set curByte ($curByte . [:tostr [:rndnum from=0 to=9] ] )
:set macAddress ($macAddress . $curByte)
}
:put $macAddress
}
We can do better ...
Each byte is an 8-bit value, so instead of just picking a random number between 00 and 99, we can pick a random number between 00 and FF. This raises the values to 256^5 or 2^40, that is more than 1000 billions possible values.
{
:local nibbleValues "0123456789abcdef"
# Fixed prefix
:local macAddress "0e"
# Add the remaining 5 bytes
for byte from=0 to=4 do={
:local curByte ":"
# Generate two digits.
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set macAddress ($macAddress . $curByte)
}
:put $macAddress
}
We can do better ...
The first nibble is itself not fixed and can be set to any 4-bit value. The number of possible values is now 2^44, or above 16 000 billions.
{
:local nibbleValues "0123456789abcdef"
# First nibble is random, second nibble is fixed
:local macAddress ([:pick $nibbleValues [:rndnum from=0 to=15] ] ."e")
# Add the remaining 5 bytes
for byte from=0 to=4 do={
:local curByte ":"
# Generate two digits. Could have done with one generation and a test
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set macAddress ($macAddress . $curByte)
}
:put $macAddress
}
We can do better ...
The only constraints is that the lower 2 bits of the lower order nibble of the first byte be 10. The higher 2 bits can be random, leading to the possibility to choose between 2,6, A and E. This raises the number of possible values to 2^46, or 64000 billions.
{
:local nibbleValues "0123456789abcdef"
# Set the first byte, random high order nibble, mostly random lower order nibble
:local macAddress ([:pick $nibbleValues [:rndnum from=0 to=15] ])
:set $macAddress ($macAddress . [:pick "26ae" [:rndnum from=0 to=3] ])
# Add the remaining 5 bytes
for byte from=0 to=4 do={
:local curByte ":"
# Generate two digits. Could have done with one generation and a test
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set curByte ($curByte . [:pick $nibbleValues [:rndnum from=0 to=15] ] )
:set macAddress ($macAddress . $curByte)
}
:put $macAddress
}
The next step, if you want, is to use the
Birthday problem/Birthday paradox to determine the probability that in a trial of
n runs, you have less than 1% chance of repeating the same MAC address.