Robbe Motmans
Robbe Motmans

Reputation: 135

How to clear all in C?

I have a simple program that makes sure another program runs 10 times in a row by using the following code:

for (i = 0; i < 10; i++)
{
  system ("shor.exe 15");   
}

The program shor.exe does indeed run 10 times; the problem is that the program is probabilistic in the sense that in one of the first steps it uses a random number generator and saves it in the variable "random" but each of the 10 runs has the same value for the variable random so I guess that it doesn't reset all variables and just uses the same generated value each run.

My question now is how do I reset/clear all the variables between each run?

Upvotes: 0

Views: 119

Answers (1)

Paul Ogilvie
Paul Ogilvie

Reputation: 25286

Your program forgets to seed the randomizer. And if it does, and it uses time(NULL) to seed the randomizer, then they are all seeded with the same seed because they are all started at the same moment: your for loop won't wait for each program to have ended and randomizers often are determinsitic, meaning the same seed implies the same sequence of random numbers.

Upvotes: 2

Related Questions