Created
February 6, 2020 13:09
-
-
Save draveness/f969452343a718d88a8a93df6ce0f2ae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
double attackerSuccessProbability(double q, int z) { | |
double p = 1.0 - q; | |
double lambda = z * (q / p); | |
double sum = 1.0; | |
int i, k; | |
for (k = 0; k <= z; k++) { | |
double poisson = exp(-lambda); | |
for (i = 1; i <= k; i++) | |
poisson *= lambda / i; | |
sum -= poisson * (1 - pow(q / p, z - k)); | |
} | |
return sum; | |
} | |
int main() { | |
for (int i = 0; i < 10; i++) { | |
printf("z=%d, p=%f\n", i, attackerSuccessProbability(0.51, i)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment