View Single Post

grallmate's Avatar


grallmate
11.04.2012 , 08:00 PM | #24
I just noticed that we both missed that I only had 185 'hits' not 195. My initial calculations were also using 9 hits as worst case (again because even a shielded subsequent hit would result in death). Doubt either of those corrections will push it up to my numbers but they will increase it noticeably.

The only adjustment I can see in your code is that you have an exit condition once the streak has reached 10

In terms of the 10 trillion iterations, I was just using an arbitrarily large number to try and generate a more average result. I intend to run it probably 100 times (most likely just add in another loop) giving me a more accurate representation.

I'll have access to my programming stuff tomorrow so I'll run them then. Probably going to take a while to run.

EDIT: Managed to get a compiler working on my work computer so I've run the program now with corrections.
Code:
int main(int argc, char *argv[])
{
	int i,j,l;
	double k = 0;
	int hits = 0;
	double count = 0;
	int maxStreak = 0;
	double prob = 4595;
	double average = 0;
	
	srand(time(NULL));

	for(l=0; l<50; l++){
	    for(i=0;i<1000000;i++){
	   		for(j=0;j<195;j++){
				k = rand() % 10000;
	      		if(k<prob){
	         		hits++;
	         		if(hits>=9){
	            		count++;
	            		if(hits>maxStreak)
	               			maxStreak = hits; 
	         		}
	      		}
	      		else
	         	hits = 0;
	  	 	}
		}
		printf("Probability: %lf\nMax Streak: %i\n", (count/i), maxStreak);
		average += (couny/i);
		count = 0;
		maxStreak = 0;
	}
	average = average / l;
	printf("Average: %lf", average);
}
Using 9 as a 'worst case' streak gives an average of about 0.178% chance of it occurring.
Using 10 gives about 0.082 chance.

Interestingly, with 1,000,000 'swings' I was consistently getting a 22-25 consecutive hits as the longest string.

I then made the following adjustment to the code to simulate 10 fights a week, every week, for a year.

Code:
int main(int argc, char *argv[])
{
	int i,j,l;
	double k = 0;
	int hits = 0;
	double count = 0;
	int weeksSeen = 0;
	int maxStreak = 0;
	double prob = 4595;
	double average = 0;
	
	srand(time(NULL));

	for(l=0; l<52; l++){
	    for(i=0;i<10;i++){
	   		for(j=0;j<195;j++){
				k = rand() % 10000;
	      		if(k<prob){
	         		hits++;
	         		if(hits>=9){
	            		count++;
	            		if(hits>maxStreak)
	               			maxStreak = hits; 
	         		}
	      		}
	      		else
	         	hits = 0;
	  	 	}
		}
		printf("Probability: %lf\nMax Streak: %i\n", (count/i), maxStreak);
		average += (count/i);
		if(count > 0)
			weeksSeen++;
		count = 0;
		maxStreak = 0;
	}
	average = average / l;
	printf("Average: %lf, Seen: %i", average, weeksSeen);
}
Average number of weeks that a worst case string was seen was about 32. Gives about a 60% chance to see it each week. Going back to 10 hits means you see it ~19 weeks of the year. Now its important to note from this version that overlapping of 11+ strings is irrelevant. For the purpose of "weeks seen" we only need to see it once each week, be it a string of 9 (10) or 20.

I then ran a seperate version that zeroed out hits every time a "worst case" string happened using the following program. This is different from yours in that it allows for multiple worst case strings in a single fight but doesn't allow for overlapping ones like my previous program (which would count 11 hits as a 2 worst case strings).

Code:
int main(int argc, char *argv[])
{
	int i,j,l;
	double k = 0;
	int hits = 0;
	double count = 0;
	int weeksSeen = 0;
	double prob = 4595;
	double average = 0;
	
	srand(time(NULL));

	for(l=0; l<50; l++){
	    for(i=0;i<1000000;i++){
	   		for(j=0;j<195;j++){
				k = rand() % 10000;
	      		if(k<prob){
	         		hits++;
	         		if(hits>=10){
	            		count++;
	            		hits = 0;
	         		}
	      		}
	      		else
	         	hits = 0;
	  	 	}
		}
		printf("Probability: %lf\n", (count/i));
		average += (count/i);
		if(count > 0)
			weeksSeen++;
		count = 0;
	}
	average = average / l;
	printf("Average: %lf, Seen: %i\n", average, weeksSeen);
}
This gave a probability of 0.044

Please double check it for me and point out any mistakes I may have made. Honestly I'm starting to get a little lost in all the numbers now. Especially since my "Weeks seen" simulation was noticeably higher than the other numbers say it should be.
The Kae-Sare Legacy - The Harbinger
<Vindication> <Retribution>

Gralleh Grall'eh Khyar
Gralleh's Guide to Guardian Tanking [UPDATED for 2.0]