Hello
I’m not familiar with mikrotik scripts. Please understand even the low level questions.
In the picture below, I want to randomly select the hexadecimal characters of number 1 and combine them with the randomly generated hexadecimal string of number 2 and finally make it like number 5.
Is there a way?
Thank you.

Why?
Where is part 1 (6 first hex of mac) coming from?
Part 2 are the 6 last hex of you random mac
Thanks for reply.
The dhcp server connected to the wan port did not assign an IP address for a specific MAC address.
So, I used the method of combining the specified values.
It seems that IP is assigned based on the oui value.
part 1 hex values are pre-specified plain text.
Here you go
{
:local array { "c8:ea:f8"; "70:9f:2d"; "38:3b:26"; "5c:fa:fb"; "9c:7b:ef" }
:local part1 ($array->[:rndnum from=0 to=([:len $array]-1)])
:local hex1 [:rndstr length=6 from="0123456789abcdef"]
:local part2 ([:pick $hex1 0 2].":".[:pick $hex1 2 4].":".[:pick $hex1 4 6])
:local Mac ($part1.":".$part2)
:put $Mac
}
Just add more mac to the array to your need.
“:” are not needed, and uppercase and lowercase are ignored (but must be a valic MAC: the 2nd digit of 1st HEX must be 0, 4, 8 or C)
:put "$[:rndstr length=1 from="0123456789ABCDEF"]$[:rndstr length=1 from="048C"]$[:rndstr length=10 from="0123456789ABCDEF"]"
Thanks to both of you for the replies.
the script works very well.
rndstr como se utiliza en la v6.48? no existe ese comando
Generate 12 times a random number
http://forum.mikrotik.com/t/random-number-between-0-and-99-or-string-between-00-and-99/149267/1
each time you do % 16 you can have random results from 0 to 15, pick from one arraythe corresponding digit.
Make sure that the 1st bit (bit 0) on 2nd digit is always 0, or the network do not work as expected…
and if is generated MAC must have 2nd bit (bit 1) on 2nd digit always 1.
: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 - 2) $lentmp]]
}
{
:local arrhex [:toarray "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F"]
:local rndmac ; :local tmp
:for x from=1 to=12 step=1 do={
:set tmp ([$randomnum] % 16)
# this makes it always a valid MAC
:if ($x = 2) do={:set tmp (($tmp | 0x2) & 0xE)}
:set rndmac "$rndmac$($arrhex->$tmp)"
:if ([:tostr [:len $rndmac]] ~ "(2|5|8|11|14)") do={:set rndmac "$rndmac:"}
}
:put $rndmac
}