Random number generator in Windows 2008 R2 & Win 2012

We plan to put into 1500 VMs' OS scheduler to run daily to make them "activate" back their
agent (could be a backup or Deep Security agent) back to the central server.  Due to unknown
reasons (could be timeout or agent failed to comms back to the server), the software vendor
can't provide a permanent fix or a 'clever' agent that could self-correct itself to re-establish
connection back to the central server (so that central server could manage them)

However, with so many VMs activating back (making Tcp connections) to the central server,
the central server may not be able to take it (ie # Tcp connections max'ed out).

For Linux, I could make the script sleep a random amt of time before activating but for
Windows, is there a random number generator?  I plan to put at the beginning of the
Windows batch script  "ping localhost -n Random_#"  (ie equiv of Linux "sleep Random_amt_time"
sunhuxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
On phone at moo but you can use %random% and use set /a to divide it smaller if needed. You can also use ping using -w param to wait that many milliseconds.

Steve
0
Steve KnightIT ConsultancyCommented:
Have a look at my scripts at http://scripts.dragpn-it.co.uk too for some others sleep scripts
0
oBdACommented:
You can configure the scheduled task as well to delay the task for a random amount of time (up to an hour).
When you edit the schedule trigger, you'll find it in Advanced Settings, "Delay task for up to ...".
Task Scheduler > Triggers
https://technet.microsoft.com/en-us/library/cc748841.aspx

If you want to go with the script, you can use the W2k3's ResKit's "sleep.exe" to actually sleep. No need to install it anywhere if you have 7zip or something similar; just unzip the downloaded .exe, then unzip sleep.exe from the rktools.msi, and drop it into the script folder or someplace in the path.
Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/en-us/download/details.aspx?id=17657

Finally, note that %random% returns a value between 0 and 32767.
The modulo operator in batch is "%", and if you want to use it in a batch file you need two of those:
set /a RandomMinutes = %Random% %% 60

Open in new window

0
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Steve KnightIT ConsultancyCommented:
Another easy "randomiser" can be to pick the last octet of the IP address say, this one uses the IP related to the default gateway which should be the user's IP address:

echo off
for /f "tokens=4 delims= " %%a in ('route print ^| find "0.0.0.0"') do for /f "tokens=1-4 delims=." %%h in ("%%a") do set host=%%k

echo %host%
pause

or

set /a num=%random% / 512

Steve
0
sunhuxAuthor Commented:
I could not get the /a right :

set aa=%random%/10
echo %aa%
9433/10


With oBDA's example, it gave missing operand:

set /a RandomMinutes = %Random% %% 60
Missing operand
0
sunhuxAuthor Commented:
This one as well ie it does not evaluated out the actual value but gave a string output:

set num=%random% / 512
22181 / 512
0
Steve KnightIT ConsultancyCommented:
From a command prompt you need to use one % rather than two for the MOD operand (remainder when dividing by 60 so will be 0 .. 59) i.e.

Set /a mins=%random% % 60
or
Set /a mins=%random% / 512

From batch you have to use %%

Steve
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.