Community discussions

 
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: 7602
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: 7602
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)

Who is online

Users browsing this forum: No registered users and 3 guests