Random Number

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.

Google is your friend.

http://forum.mikrotik.com/t/pseudo-random-number-generator-script-mersenne-twister/51962/1

I was hoping for something simpler such as just using two least significant digits of “total sector writes”.

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!

Removed

Jotne, that’s not true and modification is not needed.

:put [ $GetRandom 100 ]
55

Just give the max value.

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.

Of course. But it’s part of my routeros scripts, so available on every device that has these scripts installed. :smiley:

Alternatively you can make it a local function (replace “:global” with “:local”) and put it at the top of your own script.