Advertisement
desdemona

randomowo

Apr 8th, 2013
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. vector<unsigned int> wektor;
  9.  
  10. vector<bool> wektor2;
  11.  
  12. unsigned int random1(unsigned int xn, unsigned int a, unsigned int c, unsigned int M)
  13. {
  14.     float tmp;
  15.     unsigned int liczba;
  16.     tmp = a*wektor[xn]+c;
  17.     liczba = (unsigned int)tmp%M;
  18.     wektor.push_back(liczba);
  19.     return liczba;
  20.  
  21. }
  22.  
  23. void random2(int i)
  24. {
  25.     bool tmp = (wektor2[i-3] + wektor2[i-7]) % 2;
  26.     wektor2.push_back(tmp);
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int main()
  33. {
  34.     unsigned int generowana;
  35.  
  36.     unsigned int x0 = 15;
  37.     unsigned int a = 69069;
  38.     int c = 1;
  39.     unsigned int M =  4294967295;
  40.     int przedzialy[] = {0,0,0,0,0,0,0,0,0,0};
  41.     int przedzialy2[] = {0,0,0,0,0,0,0,0,0,0};
  42.  
  43.  
  44.  
  45.     wektor.push_back(15);
  46.  
  47.  
  48.  
  49.     wektor2.push_back(0);
  50.     wektor2.push_back(1);
  51.     wektor2.push_back(1);
  52.     wektor2.push_back(1);
  53.     wektor2.push_back(0);
  54.     wektor2.push_back(1);
  55.     wektor2.push_back(1);
  56.  
  57.     for(int i = 0; i < 100000; i++)
  58.     {
  59.         unsigned int randomowa1 = random1(i,a,c,M);
  60.         przedzialy[randomowa1/(M/10)]++;
  61.     }
  62.  
  63.  
  64.  
  65.  
  66.     for(int i = 0; i < 10; i++)
  67.     {
  68.         cout << przedzialy[i] << "\n";
  69.  
  70.     }
  71.  
  72.     cout << "Druga czesc\n";
  73.    
  74.     for(int i = 7; i < 100032; i++)
  75.     {
  76.         random2(i);
  77.     }
  78.  
  79.     for(int i = 0; i < 100000; i++)
  80.     {
  81.         unsigned int randomowa2 = 0;
  82.         for(float j = 0; j < 32; j++)
  83.         {
  84.              randomowa2 += (wektor2[i+j] * pow(2,j));
  85.         }
  86.         przedzialy2[randomowa2/(M/10)]++;
  87.     }
  88.  
  89.  
  90.     for(int i = 0; i < 10; i++)
  91.     {
  92.         cout << przedzialy2[i] << "\n";
  93.     }
  94.  
  95.     int z;
  96.     cin >> z;
  97.  
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement