Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- class generatorLin
- {
- private:
- unsigned int a,c,m;
- vector <unsigned int> words;
- unsigned int it;
- public:
- generatorLin(unsigned int aa,unsigned int cc,unsigned int mm, unsigned int seed)
- {
- this->a = aa;
- this->c = cc;
- this->m = mm;
- it = 1;
- this->words.push_back(seed);
- }
- unsigned int randlin()
- {
- this->words.push_back(0);
- this->words[this->it] = (this->words[this->it-1] * this->a + this->c)%m;
- this->it++;
- return this->words[this->it -1];
- }
- };
- class zliczacz
- {
- private:
- unsigned int n,m;
- vector<unsigned int> tab;
- public:
- zliczacz(unsigned int nn, unsigned int mm)
- {
- tab.resize(nn);
- for(unsigned int i=0;i<nn;i++)
- tab[i] = 0;
- this->n = nn;
- this->m = mm;
- return ;
- }
- void zlicz(unsigned int num)
- {
- tab[num/(this->m/this->n)] ++;
- return ;
- }
- void print()
- {
- for(unsigned i =0;i<this->n;i++)
- cout << i* (this->m/n) << " - " << this->tab[i] << endl;
- }
- };
- class generatorTurbo
- {
- private:
- vector<bool> words;
- unsigned int p,q;
- public:
- generatorTurbo()
- {
- words.push_back(0);
- words.push_back(1);
- words.push_back(1);
- words.push_back(1);
- words.push_back(0);
- words.push_back(1);
- words.push_back(1);
- p = 3;
- q = 7;
- return;
- }
- public:
- unsigned int randTurbo()
- {
- unsigned int a,b;
- for(int i = 0; i <32; i++)
- {
- a = words[words.size()-p];
- b = words[words.size()-q];
- words.push_back((a+b)%2);
- }
- unsigned int num = 0;
- unsigned int eee = 1;
- for(int i = 32; i>0;i--)
- {
- num += words[words.size()-i] * eee;
- eee*=2;
- }
- return num;
- }
- };
- int main()
- {
- generatorLin a((int)69069, 1, (int)pow((double)2,(double)31)-1, 15);
- zliczacz b(10, (int)pow((double)2,(double)31)-1);
- for(unsigned int i =0 ; i<100000; i++)
- b.zlicz(a.randlin());
- b.print();
- cout << "========================" << endl;
- unsigned zakres = -1;
- generatorTurbo c;
- zliczacz d(10, zakres);
- for(unsigned int i =0 ; i<100000; i++)
- {
- if(i%1000 == 0)
- cout << i << endl;
- d.zlicz(c.randTurbo());
- }
- d.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement