The "name" in [/interface find name] is completely useless.
Is easy obtain a random number between 1 to 254 (or 0 to 255)...
v7 only
:put [:rndnum from=1 to=254]
v6 only
viewtopic.php?f=9&t=175453&p=858629#p858629
:global randomnum do={
/system resource irq
:local tmpsum 0
:foreach i in=[find] do={:set tmpsum ($tmpsum + [get $i count])}
:set tmpsum [:tostr $tmpsum]
:local lentmp [:len $tmpsum]
:return [:tonum [:pick $tmpsum ($lentmp - 3) $lentmp]]
}
:put ([$randomnum % 255])
The script must check if the new IP is the same IP as before: ~%2,5 of the possibility of the same number is too high...
This fail if ether1, for some reason, have multiple IPs
/ip address set [ find interface="ether1" ] address=$newIP
must be something like:
/ip address set [find where interface="ether1" and address=$oldIP] address=$newIP
and $oldIP is also used for check if is set the same previous IP...
For obtain easily a random number on v6, using the sum of tx-byte as base, this is more easy than all those calculations you put on script.
{
:local total 0
/interface
:foreach item in=[find] do={
:set total ($total + [get $item tx-byte])
}
:put ($total % 255)
}
Your method and this have the same identical probability to produce same number on two (or more) consecutive calls, if no tx happen...