Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- #define MAX_ITER 1000000
- #define K 1024
- typedef unsigned long long int uint64;
- int main() {
- const double norm = 100. / MAX_ITER;
- const double Cst = 100. / log(2.);
- int n;
- uint64 histo[K] = { 0 };
- const double alpha = 1.9; // slope in (1.0, 2.0)
- double y = 1.; // anything in [1., 4./alpha)
- for (n = 0; n < MAX_ITER; ++n) {
- y = y * alpha;
- if (y > 2.) y *= 0.5;
- ++histo[(int)(y * K) - K];
- }
- // print histo along with theoretical distribution 1 / x.ln(2)
- for (n = K; n < 2 * K; ++n) {
- printf("%d %.5lf %.5lf\n", n, norm * histo[n - K], Cst / n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement