vakho

Modelirebis Sak2 [Giorgi's]

Dec 15th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int simulac(int a,int b, int q){
  6.     int n = pow(2.0,b);
  7.     int m = n-q;    
  8.     int k = a/n;
  9.     int z = a%n;
  10.     int t = z + k*q;
  11.     while( t >= m )
  12.            t-= m;
  13.     return t;  
  14. }
  15.  
  16. int simulac1(int a,int b, int q){
  17.     int n = 1<<b;
  18.     int m = n-q;    
  19.     int k = a>>b;
  20.     int z = a&(~(~0<<b));
  21.     int t = z + k*q;
  22.     while( t >= m )
  23.            t-= m;
  24.     return t;        
  25. }
  26.  
  27. int generator(int z){
  28.     int a=5;
  29.     int c=3;
  30.     int m=64;
  31.     int b=6;
  32.    
  33.     int sum=(a*z+c);
  34.     return sum&(~(~0<<b));        
  35. }
  36.  
  37. int diskretul( double g ){
  38.     if( g>= 0.1 && g <0.7 )
  39.         return 0;
  40.     if( g>=0.8)
  41.         return 10;
  42.     if( g<0.1)
  43.         return -1;
  44.     return 7;
  45. }
  46.  
  47. double uwyveti( double g ){
  48.     return -log(2.34)/log(1-g);
  49. }
  50.  
  51. int main(int argc, char *argv[])
  52. {
  53.     printf("\t 1 * 4         = %d \n ", 1*4 );
  54.     printf("\t 1 << 2        = %d \n\n", 1<<2 );
  55.    
  56.     printf("\t 16 / 4        = %d \n ", 16/4 );
  57.     printf("\t 16 >> 2       = %d \n\n", 16>>2 );
  58.    
  59.     printf("\t (15)mod 5     = %d \n ", 15% 4 );
  60.     printf("\t 15&(~(~0<<2)) = %d \n\n", 15&(~(~0<<2)) );  
  61.    
  62.    
  63.     int a = 87;
  64.     int n = 16;
  65.     int q = 1;
  66.     printf("\n\t (a)mod(2^b-q)    = %d", a%(n-1));
  67.    
  68.     printf("\n\n\t simulac(87,4,1)  = %d", simulac(a,4,q));  
  69.    
  70.     printf("\n\n\t simulac1(87,4,1) = %d\n\n", simulac1(a,4,q));
  71.    
  72.     int z = 1;
  73.     int i=0;
  74.     while(i<10){
  75.             z =  generator(z);
  76.             printf(" g = %d", z/63.0 );
  77.             printf(" %d : %d\n\n",i,diskretul( z/63.0 ));
  78.             printf(" %d : %d\n\n",i,uwyveti( z/63.0 ));
  79.              
  80.             i++;
  81.     }
  82.  
  83.    
  84.    
  85.              
  86.     system("PAUSE");
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment