Advertisement
desdemona

nie mam przyjaciol

Apr 9th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <vector>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. //vector<unsigned int> wektor;
  10. vector<double> wektor;
  11. vector<int> wektor2;
  12.  
  13. //unsigned int random1(unsigned int xn, unsigned int a, unsigned int c, unsigned int M)
  14. //{
  15. //    float tmp;
  16. //  unsigned int liczba;
  17. //  tmp = a*wektor[xn]+c;
  18. //  liczba = (unsigned int)tmp%M;
  19. //  wektor.push_back(liczba);
  20. //  return liczba;
  21. //
  22. //}
  23. //
  24. //void random2(int i)
  25. //{
  26. //  bool tmp = (wektor2[i-3] + wektor2[i-7]) % 2;
  27. //  wektor2.push_back(tmp);
  28. //}
  29.  
  30.  
  31.  
  32.  
  33. int main()
  34. {
  35.     //unsigned int generowana;
  36.  
  37.     //unsigned int x0 = 15;
  38.     //unsigned int a = 69069;
  39.     //int c = 1;
  40.     //unsigned int M =  4294967295;
  41.     int przedzialy[] = {0,0,0,0,0,0,0,0,0,0};
  42.     int przedzialy3[] = {0,0,0,0,0,0,0,0,0,0};
  43.     int przedzialy2[] = {0,0,0,0};
  44.  
  45.     //wektor.push_back(15);
  46.  
  47.  
  48.     //wektor2.push_back(0);
  49.     //wektor2.push_back(1);
  50.     //wektor2.push_back(1);
  51.     //wektor2.push_back(1);
  52.     //wektor2.push_back(0);
  53.     //wektor2.push_back(1);
  54.     //wektor2.push_back(1);
  55.  
  56.     //for(int i = 0; i < 100000; i++)
  57.     //{
  58.     //  unsigned int randomowa1 = random1(i,a,c,M);
  59.     //  przedzialy[randomowa1/(M/10)]++;
  60.     //}
  61.  
  62.  
  63.     //for(int i = 0; i < 10; i++)
  64.     //{
  65.     //  cout << przedzialy[i] << "\n";
  66.  
  67.     //}
  68.  
  69.     //cout << "Druga czesc\n";
  70.     //
  71.     //for(int i = 7; i < 100032; i++)
  72.     //{
  73.     //  random2(i);
  74.     //}
  75.  
  76.     //for(int i = 0; i < 100000; i++)
  77.     //{
  78.     //  unsigned int randomowa2 = 0;
  79.     //  for(float j = 0; j < 32; j++)
  80.     //  {
  81.     //       randomowa2 += (wektor2[i+j] * pow(2,j));
  82.     //  }
  83.     //  przedzialy2[randomowa2/(M/10)]++;
  84.     //}
  85.  
  86.  
  87.     //for(int i = 0; i < 10; i++)
  88.     //{
  89.     //  cout << przedzialy2[i] << "\n";
  90.     //}
  91.  
  92.    
  93.      srand (time(NULL));
  94.      double liczba = (rand() % 100000)/100000;
  95.      int n = 100000;
  96.      //int n=10;
  97.      for(int i=0; i<n; i++)
  98.      {
  99.          wektor.push_back((double) rand() / (RAND_MAX));
  100.          //cout << wektor[i] << "\n";
  101.          wektor[i] = wektor[i] * 100 + 10;
  102.          przedzialy[(int)((wektor[i])/10) -1]++;
  103.      }
  104.  
  105.     for(int i = 0; i < 10; i++)
  106.     {
  107.         cout << przedzialy[i] << "\n";
  108.     }
  109.     cout << "\n\n";
  110.     for(int i=0; i<n; i++)
  111.     {
  112.         double liczba= ((double) rand() / (RAND_MAX));
  113.         if(liczba < 0.25)
  114.         {
  115.             wektor2.push_back(1);
  116.             przedzialy2[0]++;
  117.         }
  118.         else if(liczba < 0.55)
  119.         {
  120.             wektor2.push_back(2);
  121.             przedzialy2[1]++;
  122.         }
  123.         else if(liczba < 0.85)
  124.         {
  125.             wektor2.push_back(3);
  126.             przedzialy2[2]++;
  127.         }
  128.         else
  129.         {
  130.             wektor2.push_back(4);
  131.             przedzialy2[3]++;
  132.         }
  133.     }
  134.  
  135.     for(int i = 0; i < 4; i++)
  136.     {
  137.         cout << przedzialy2[i] << "\n";
  138.     }
  139.  
  140.     double h = 0.02;
  141.     double a= -0.0002;
  142.     double b = 0.022;
  143.     double rand1_osx=0;
  144.     double rand2_osy=0;
  145.     cout << "\n\n";
  146.     int i=0;
  147.     while(i<n)
  148.     {
  149.         rand1_osx= ((double) rand() / (RAND_MAX)) * 100 + 10;
  150.         //od 10 do 110
  151.  
  152.         rand2_osy= ((double) rand() / (RAND_MAX)) * (h+0.0001);
  153.         //od zera do h
  154.  
  155.         //podstawiamy do wzoru
  156.         if(rand2_osy < (a*rand1_osx + b))
  157.         {
  158.             i++;
  159.             przedzialy3[(int)((rand1_osx)/10) -1]++;
  160.         }
  161.     }
  162.  
  163.    
  164.     for(int i = 0; i < 10; i++)
  165.     {
  166.         cout << przedzialy3[i] << "\n";
  167.     }
  168.     return 0;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement