user1026561
user1026561

Reputation: 81

Running program multiple times using batch script

I have a program I wrote that I need to run multiple times. I tried writing a batch script to do this but it's not working correctly.

I tried using

@echo off
start polymer.exe
start polymer.exe

and also tried

@echo off
for /l %%X in (1,1,2) do (start polymer.exe)

polymer.exe writes a number out to a file every time it is run and very rarely will 2 numbers be identical but when I run these scripts I get two identical numbers in the output. Any ideas why this is happening?

OS is Windows 7

Upvotes: 3

Views: 2741

Answers (2)

JRL
JRL

Reputation: 77995

If your exe generates a random number based on the time, and you can't modify it, you can insert a pause statement in the batch script between the calls.

You can emulate a wait like this (will pause 3 seconds):

PING 127.0.0.1 -n 4

Upvotes: 0

Ken Cheung
Ken Cheung

Reputation: 1808

Seems like you forget to initialize your random number generator.

C : srand((unsigned)(time(NULL)));

C# : Random rand = new Random((int)DateTime.Now.Ticks);

Upvotes: 1

Related Questions