Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int simulac(int a,int b, int q){
- int n = pow(2.0,b);
- int m = n-q;
- int k = a/n;
- int z = a%n;
- int t = z + k*q;
- while( t >= m )
- t-= m;
- return t;
- }
- int simulac1(int a,int b, int q){
- int n = 1<<b;
- int m = n-q;
- int k = a>>b;
- int z = a&(~(~0<<b));
- int t = z + k*q;
- while( t >= m )
- t-= m;
- return t;
- }
- int generator(int z){
- int a=5;
- int c=3;
- int m=64;
- int b=6;
- int sum=(a*z+c);
- return sum&(~(~0<<b));
- }
- int diskretul( double g ){
- if( g>= 0.1 && g <0.7 )
- return 0;
- if( g>=0.8)
- return 10;
- if( g<0.1)
- return -1;
- return 7;
- }
- double uwyveti( double g ){
- return -log(2.34)/log(1-g);
- }
- int main(int argc, char *argv[])
- {
- printf("\t 1 * 4 = %d \n ", 1*4 );
- printf("\t 1 << 2 = %d \n\n", 1<<2 );
- printf("\t 16 / 4 = %d \n ", 16/4 );
- printf("\t 16 >> 2 = %d \n\n", 16>>2 );
- printf("\t (15)mod 5 = %d \n ", 15% 4 );
- printf("\t 15&(~(~0<<2)) = %d \n\n", 15&(~(~0<<2)) );
- int a = 87;
- int n = 16;
- int q = 1;
- printf("\n\t (a)mod(2^b-q) = %d", a%(n-1));
- printf("\n\n\t simulac(87,4,1) = %d", simulac(a,4,q));
- printf("\n\n\t simulac1(87,4,1) = %d\n\n", simulac1(a,4,q));
- int z = 1;
- int i=0;
- while(i<10){
- z = generator(z);
- printf(" g = %d", z/63.0 );
- printf(" %d : %d\n\n",i,diskretul( z/63.0 ));
- printf(" %d : %d\n\n",i,uwyveti( z/63.0 ));
- i++;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment