Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #define SIZE 8
- int ArrayRand[SIZE] = {1, 7, 11, 12, 15, 37, 98, 101};
- int simulatedDivision(int a, int b, int q)
- {
- int zi = a;
- int modul = (1 << b) - q;
- int k = zi >> b;
- zi = zi & (~(~0 << b));
- zi += k*q;
- while (zi >= modul)
- zi -= modul;
- return zi;
- }
- #define a 101
- #define c 1
- #define m 128 // 2^7
- int linearCongruentialGenerator(int zi_1)
- {
- int zi = zi_1;
- return (a*zi + c) & (~(~0 << 7));
- }
- int discrete(float num)
- {
- if (num > 0 && num <= 0.22) return 21;
- if (num > 0.22 && num <= 0.39) return 10;
- if (num > 0.39 && num < 1) return 18;
- return -1; // Shecdoma?
- }
- int main()
- {
- system("COLOR F0");
- int i = 0;
- while (i < SIZE)
- {
- printf("ArrayRand[%d] = \t\t%d\t", i, ArrayRand[i]);
- ArrayRand[i] = linearCongruentialGenerator(ArrayRand[i]);
- printf("ArrayRand[%d] = \t%f\n", i, ( ArrayRand[i]/(float)m ));
- i++;
- }
- printf("\n\n");
- i = 0;
- while (i < SIZE)
- {
- printf("Discrete[%d] = \t%d\n", i, discrete( ArrayRand[i]/(float)m ));
- i++;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment