Calculating Error Rate for Valid Results: A Wins Over 99.9% of the Time

  • Thread starter Thread starter magnifik
  • Start date Start date
  • Tags Tags
    Error Percent
AI Thread Summary
The discussion centers on calculating the error rate needed for a scenario where 999 out of 1000 results are valid, equating to a 99.9% validity rate. The code provided attempts to simulate outcomes for two entities, A and B, with an adjustable error rate that influences the results. Participants noted that the code's logic and output were unclear, particularly regarding how the error rate was being incremented and its impact on the results. It was suggested to treat the error rate as a constant rather than a loop counter to yield more meaningful output. The conversation emphasizes the need for clarity in defining the problem and the code's intended functionality.
magnifik
Messages
350
Reaction score
0
there are 1000 valid results, but 1 is invalid. in other words, 99.9% of the results are valid. what is the error rate for this to be possible?

basically right now i have these facts -- if A has more than B, A wins. in order for a result to be considered "valid," A must have more wins than B. below is a code with 15% error rate. my question is how do i find the error rate for the above restraints?

Code:
int main(){
	int A = 0;
	int B = 0;
	int aWins = 0;
        int errorPercent = 15; // errorPercent% of the time, the comparison will be incorrect

	srand(time(0));
	for (int j = 0; j < 1000; j++){
	for (int i = 0; i < 1000000; i++){
		if ((rand()%2) == 0)
                        if( (rand()%100) + 1 > errorPercent )
			      B++;
                         else
                               A++;
		else
                        if( (rand()%100) + 1 > errorPercent )
			      A++;
                         else
                              B++;
	}
	if (A > B)
		aWins++;
	}
 
Physics news on Phys.org
If you have 1000 valid results, then all one thousand of them are valid. There can't be any invalid results if all of them are valid results.

If you have 1000 results and one of them is invalid, then 99.9% of the results are valid.

What are you asking here? The only variable you have any control over is the errorPercent, so maybe you are supposed to try different values for this variable to see what happens.

You aren't being very clear on what you need to do, so if you want a better answer, you need to tell us exactly what problem you're trying to solve.
 
i meant of the 1000 results, 999 are valid, 1 is invalid. that's the problem I'm having...the specs aren't very specific
 
And your question isn't very clear. What's the problem you're trying to solve?

How do you know what result your program produces? There are no output statements.
 
this is what I'm trying to do right now. i have it set up where 1000000 choose either A or B. the errorRate variable dictates whether or not the choices were swapped. i have it set up so the errorRate gets incremented until A is less than B (because A is supposed to be greater than B in this game). however, when i try to run it... it just prints 1000000000. when i try to enter the errorRate manually, A is finally less than B around the errorRate of 42. what am i doing wrong in my code??

Code:
int errorRate = 0;
int A = 510000;
int B = 490000;
for (int z = 0; z < 1000; z++){
	for (int x = 0; x < 1000000; x++){
		if ((rand()%2) == 0){
			if ((rand()%100) + 1 <= errorRate){
				B--;
				A++;
			}
		}
		else{
			if ((rand()%100) + 1 <= errorRate){
				A--;
				B++;
			}
		}
	}
	errorRate++;
	if (A < B)
		break;
}
cout << errorRate << endl;
 
magnifik said:
this is what I'm trying to do right now. i have it set up where 1000000 choose either A or B. the errorRate variable dictates whether or not the choices were swapped. i have it set up so the errorRate gets incremented until A is less than B (because A is supposed to be greater than B in this game). however, when i try to run it... it just prints 1000000000. when i try to enter the errorRate manually, A is finally less than B around the errorRate of 42. what am i doing wrong in my code??

Code:
int errorRate = 0;
int A = 510000;
int B = 490000;
for (int z = 0; z < 1000; z++)
{
   for (int x = 0; x < 1000000; x++)
   {
       if ((rand()%2) == 0)
      {
         if ((rand()%100) + 1 <= errorRate)
         {
            B--;
            A++;
         }
      }
      else
      {
         if ((rand()%100) + 1 <= errorRate)
         {
            A--;
            B++;
         }
      }
   }
   errorRate++;
   if (A < B)
   break;
}
cout << errorRate << endl;

Each time the inner loop finishes an iteration, you increment errorRate (which starts at 0). By the time the outer loop is finished, errorRate will have been incremented to 1,000,000,000. No surprise there.

Instead of using errorRate as a glorified loop counter, I would suggest treating it as a constant that you set, and displaying something more useful, like A and B.
 

Similar threads

Back
Top