I’m writing a script (01) which will then be applied on various different routers.
This script (01) adds in routeros a script (02) and a scheduler that activates this script (02). I would like the execution time of this new script (02) to be differentiated on each of the routers on which it will be active.
Is there a way to generate a random time every time that script (01) is run?
Is there any way to convert an arbitrary string to an integer?
I looked at your request and thought about adding a random time in the future. I would set a time range from a set time (now/future) to a second one set in future.Then generate a random number in that range.
I would use two EPOCH times and deduct max from low to get the range. Count the digits and generate a random number fitting that number of digits. Deduct this random from the max time.
If the result time is lower than the low time do it over till it fits or quick and dirty, divide the random result time by a random divider.
…or I could add ownbase-range as [6-24] as a number between 6 and 24. 6 Is the current hour or a current hour of 4+2 generating a time that lays 2 hours in the future.
Hmmm I am still in the thinking/design mode for the time part. The main challenge is to transferring and interpreting the parameters. I have already a idea to implement it and it is not that difficult going step by step. I will post when I am ready and in the meantime you keep using your version.
Yours is dedicated to time and I am extending my version with time. My version does a lot more which you don’t need right now.
If you want near-random time, but near-unique for upload some file on some ftp and you not want congestionate connection for do that all at the same time,
you can use the last 3 octet of original ether1 MAC address like:
So, for each one from 0 to 99, each number is 144 seconds
: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 randomtime (01:00:00 + [:totime (([$randomnum] + 1) * 144)])
:put $randomtime
}
On MAC, % 4 can produce 0, 1, 2 or 3, so the intervai si from 01:00:00 to 04:59:59
{
:local Gorimac [/int eth get ether1 orig-mac-address]
:local shour (([:tonum (“0x”.[:pick $Gorimac 9 11])] % 4) + 1)
:local smin ( [:tonum (“0x”.[:pick $Gorimac 12 14])] % 60 )
:local ssec ( [:tonum (“0x”.[:pick $Gorimac 15 17])] % 60 )