Community discussions

MikroTik App
 
gwzph
just joined
Topic Author
Posts: 6
Joined: Sun Sep 24, 2006 10:11 am

Scripts for random?

Sun Nov 05, 2006 8:11 am

Hi,guys

Is there any way to generate a random number(integer) with MT scripts?

thx
 
User avatar
raivis-v
Frequent Visitor
Frequent Visitor
Posts: 55
Joined: Thu Jul 14, 2005 10:21 am
Location: Latvia, Riga

Re: Scripts for random?

Tue Dec 05, 2006 9:40 am

Hi,guys

Is there any way to generate a random number(integer) with MT scripts?

thx
Nope, it is not possible to generate rundom number with MT script at this moment, but rundom number generation will be implemented later in routerOS v 3.0
 
gwzph
just joined
Topic Author
Posts: 6
Joined: Sun Sep 24, 2006 10:11 am

Thu Jan 25, 2007 5:27 am

THX!
 
User avatar
greek
Member Candidate
Member Candidate
Posts: 120
Joined: Thu Nov 04, 2010 11:37 pm
Location: Russia, 78rus

Re: Scripts for random?

Tue Apr 21, 2015 3:17 pm

Is it done?
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Scripts for random?

Tue Apr 21, 2015 3:21 pm

Nope. 9 years later, there's still no way in RouterOS scripting to generate a random number.

The closest thing you can do is an HTTP(S) request to random.org with "/tool fetch", and use that.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Tue Apr 21, 2015 3:31 pm

Or to somehow calculate it.
 
User avatar
strods
MikroTik Support
MikroTik Support
Posts: 1661
Joined: Wed Jul 16, 2014 7:22 am
Location: Riga, Latvia

Re: Scripts for random?

Tue Apr 21, 2015 3:37 pm

Yes, random number feature is not implemented but sometimes it is worth to remember that this is router :D

Why do not generate this number by yourself? For example, use clock to get random number:

{
:local sum 0
:local time [/system clock get time]
:set sum [:pick $time 0 2]
:set sum ($sum * [:pick $time 3 5])
:set sum ($sum * [:pick $time 6 8])
:local random [:pick $sum 0 1]
:put ("This is you random number - ". $random)
}
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Scripts for random?

Tue Apr 21, 2015 3:39 pm

I've seen some scripts that calculate a pseudo-random number but I wasn't very happy / confident in their randomness.

Nope. 9 years later, there's still no way in RouterOS scripting to generate a random number.

The closest thing you can do is an HTTP(S) request to random.org with "/tool fetch", and use that.
Brilliant!
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Scripts for random?

Tue Apr 21, 2015 3:40 pm

Yes, random number feature is not implemented but sometimes it is worth to remember that this is router :D
But what if we want to block websites by redirecting our users to a random shock website?
:lol:
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: Scripts for random?

Tue Apr 21, 2015 3:44 pm

Yes, random number feature is not implemented but sometimes it is worth to remember that this is router :D

Why do not generate this number by yourself? For example, use clock to get random number
This is only sufficient if you need one random number per second. If you need several per second, it's not enough, since the clock is only accurate up to a second.

Also, that calculation above is definitely not random at all (the result predictably grows with each second, and only decreases a little back every hour, and decreases further more every day, growing back by the end of the day)... Though I see your point that it could be used as a seed for further calculations that then make the result appear random. Those further calculations are more taxing on the router though.


One possible algorithm inside the router can be this MD5 generator applied over the clock.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Wed Apr 22, 2015 11:48 am

You can use any number inputs to calculate whatever. For example interface packet counters are such useful values. But real random seed would be much better.