Scripts for random?

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

THX!

Is it done?

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.

Or to somehow calculate it.

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

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)
}

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


Brilliant!

But what if we want to block websites by redirecting our users to a random shock website?
:laughing:

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.

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.