Advertisement
Guest User

dynamic system, 1/x stationary distribution

a guest
Nov 17th, 2014
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <math.h>
  2. #include <stdio.h>
  3. #include <assert.h>
  4.  
  5. #define MAX_ITER 100000000
  6. #define K 1024
  7. #define B 7  
  8.  
  9. typedef unsigned long long int uint64;
  10. typedef unsigned long int uint32;
  11. int main() {
  12.   const int SHIFT = ((int)(log(B)/log(2.)));
  13.   const int THRESH = (2 * K) << SHIFT;  
  14.   const double norm = 100. / MAX_ITER;  
  15.  
  16.   uint64 histo[K] = { 0 };
  17.   uint32 x =  2 * K - 1;
  18.  
  19.   int n;
  20.   for (n = 0; n < MAX_ITER; ++n) {
  21.     x = x * B + (rand() % B);
  22.     const int shift = SHIFT + (x >= THRESH);
  23.     x >>= shift;
  24.     assert(x >= K && x < 2 * K);
  25.     ++histo[x - K];  
  26.   }
  27.  
  28.   // print histo
  29.   for (n = 0; n < K; ++n) {
  30.     printf("%d %.5lf\n", n + K, norm * histo[n]);
  31.   }
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement