hci
September 3, 2019, 7:57pm
1
I would like to generate a simple random number between 1 and 100. If the result is “1” I would like to continue running the script. Anything else and I would like to exit. Anyone know of a way to do that?
The goal is that there is an approximately 1 percent chance the script will run every time it is called.
Jotne
September 3, 2019, 8:26pm
2
hci
September 3, 2019, 9:27pm
3
I was hoping for something simpler such as just using two least significant digits of “total sector writes”.
eworm
September 4, 2019, 4:51am
4
Sector writes change too seldom.
How about this one?
https://git.eworm.de/cgit/routeros-scripts/tree/global-functions#n278
Remember that is still a very weak algorithm!
eworm
September 4, 2019, 5:29am
6
Jotne, that’s not true and modification is not needed.
:put [ $GetRandom 100 ]
55
Just give the max value.
Jotne
September 4, 2019, 5:37am
7
Sorry did not test it that way.
If you use it a a global function I assume its gone after reboot. So you need some script to restore it.
eworm
September 4, 2019, 6:44am
8
Of course. But it’s part of my routeros scripts , so available on every device that has these scripts installed.
Alternatively you can make it a local function (replace “:global” with “:local”) and put it at the top of your own script.