Community discussions

MikroTik App
 
serg87i
just joined
Topic Author
Posts: 7
Joined: Tue Aug 06, 2013 11:07 am

Generate random numbers

Mon May 19, 2014 3:05 pm

Hi all! (sorry for my bad english). I have a script:
{
/tool sniffer stop
local 1 [pick [sys clock get date ] 0 3]
local 2 [pick [sys clock get date ] 4 6]
loca 3 [pick [sys clock get date ] 7 12]
local time [/system clock get time]
local date "$2$1$3"
local status [/tool sniffer get running]
if ($status = false ) do={ put $time; put $date; tool sniffer set file-name="usb1/$date, 4" ; / tool sniffer start}
}

This script start packet sniffer and add system date to the name of file. In my router SNMP Client didn't work because router is setting in bridge. That's why i need add random number to the filename. How to create it? Thanks...
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Generate random numbers

Mon May 19, 2014 4:39 pm

 
serg87i
just joined
Topic Author
Posts: 7
Joined: Tue Aug 06, 2013 11:07 am

Re: Generate random numbers

Mon May 19, 2014 5:27 pm

Thank you. But its very difficult for me. How can i make it easier? I know that in c++ the function name is rand().
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: Generate random numbers

Mon May 19, 2014 5:50 pm

Well, depends on how much "random" your number should be. As far as I kow, there is no ROS command for generation random numbers. Therefore you have to take some numbers and do some math operation with them in order to get random number.

If you would like to have one digit from 0-9 interval, I could imagine for example to summarize all digits from date+time + add some number that is really changing - e.g. actual number of connections (or even more such numbers) and take last digit of the sum. This could be easy and maybe close to random number.

It also depends on how many random numbers and how often you will need...

Take it as an idea that could help, nothing I have done already.
 
p1p1p1
just joined
Posts: 22
Joined: Sat Feb 23, 2013 1:53 pm

Re: Generate random numbers

Mon Sep 17, 2018 9:34 pm

simple random number = cpu load :D just multiple it to get required range :P

example:

:delay ([/system resource get cpu-load ] *8)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12554
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Generate random numbers

Sat May 22, 2021 7:32 pm

simple random number = cpu load :D just multiple it to get required range :P

example:

:delay ([/system resource get cpu-load ] *8)
Nice hint, but on my powerful machineis everityme is between 2 and 3 ....
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12554
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Generate random numbers

Sat May 22, 2021 7:54 pm

I write my own version:

Random number between 0 and 99 or string between 00 and 99
viewtopic.php?f=9&t=175453&p=858629

Who is online

Users browsing this forum: No registered users and 3 guests