Page 1 of 1

Random Number

Posted: Tue Sep 03, 2019 10:57 pm
by hci
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.

Re: Random Number

Posted: Tue Sep 03, 2019 11:26 pm
by Jotne
Google is your friend.

viewtopic.php?f=9&t=56933

Re: Random Number

Posted: Wed Sep 04, 2019 12:27 am
by hci
I was hoping for something simpler such as just using two least significant digits of "total sector writes".

Re: Random Number

Posted: Wed Sep 04, 2019 7:51 am
by eworm
Sector writes change too seldom.

How about this one?
https://git.eworm.de/cgit/routeros-scri ... tions#n278

Remember that is still a very weak algorithm!

Re: Random Number

Posted: Wed Sep 04, 2019 8:06 am
by Jotne
Removed

Re: Random Number

Posted: Wed Sep 04, 2019 8:29 am
by eworm
Jotne, that's not true and modification is not needed.
:put [ $GetRandom 100 ]
55
Just give the max value.

Re: Random Number

Posted: Wed Sep 04, 2019 8:37 am
by Jotne
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.

Re: Random Number

Posted: Wed Sep 04, 2019 9:44 am
by eworm
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. :D

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