Community discussions

 
hci
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri May 28, 2004 5:10 pm

Random Number

Tue Sep 03, 2019 10:57 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1303
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Random Number

Tue Sep 03, 2019 11:26 pm

Google is your friend.

viewtopic.php?f=9&t=56933
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
hci
Long time Member
Long time Member
Topic Author
Posts: 594
Joined: Fri May 28, 2004 5:10 pm

Re: Random Number

Wed Sep 04, 2019 12:27 am

I was hoping for something simpler such as just using two least significant digits of "total sector writes".
 
User avatar
eworm
Member
Member
Posts: 393
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Random Number

Wed Sep 04, 2019 7:51 am

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!
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1303
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Random Number

Wed Sep 04, 2019 8:06 am

Removed
Last edited by Jotne on Wed Sep 04, 2019 8:36 am, edited 1 time in total.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
eworm
Member
Member
Posts: 393
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Random Number

Wed Sep 04, 2019 8:29 am

Jotne, that's not true and modification is not needed.
:put [ $GetRandom 100 ]
55
Just give the max value.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1303
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: Random Number

Wed Sep 04, 2019 8:37 am

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.
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
eworm
Member
Member
Posts: 393
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Random Number

Wed Sep 04, 2019 9:44 am

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.
Manage RouterOS scripts and extend your devices' functionality: RouterOS Scripts

Who is online

Users browsing this forum: Baidu [Spider], MSN [Bot] and 9 guests