Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <chrono>
- double pmax = 0.18;
- using namespace std;
- random_device rd;
- mt19937 mt(rd());
- random_device rand1, rand2;
- mt19937 mt1(rand1()), mt2(rand2());
- uniform_real_distribution<double> dist(0.0, 1.0);
- uniform_int_distribution<int> dist1(0, 5);
- uniform_real_distribution<double> dist2(0.0, pmax);
- void odwracanie() {
- int tab[6], counter = 0, amount = 200000, temp1, amountHit = 0;
- double tabProc[6] = { 0.16, 0.17, 0.18, 0.17, 0.165, 0.155 };
- for (int i = 0; i < 6; i++)
- tab[i] = 0;
- while (true) {
- temp1 = dist1(mt1);
- if (dist2(mt2) <= tabProc[temp1]) {
- tab[temp1]++;
- amountHit++;
- }
- if (amountHit > amount)
- break;
- }
- for (int i = 0; i < 6; i++)
- cout << (double)tab[i] / (double)amount * (double)100 << " ";
- }
- void eliminacja() {
- int tab[4], size = 4, amount = 200000;
- double random;
- for (int i = 0; i < size; i++) {
- tab[i] = 0;
- }
- for (int i = 0; i < 200000; i++) {
- random = dist(mt);
- if (random < 0.8)
- tab[0]++;
- else if (random < 0.9)
- tab[1]++;
- else if (random < 0.96)
- tab[2]++;
- else
- tab[3]++;
- }
- for (int i = 0; i < size; i++) {
- cout << (double)tab[i] / (double)amount * (double)100 << " ";
- }
- }
- int main() {
- std::chrono::duration<double> czas;
- auto poczatek = std::chrono::high_resolution_clock::now();
- odwracanie();
- auto koniec = std::chrono::high_resolution_clock::now();
- czas = koniec - poczatek;
- std::cout << std::fixed << "czas odwracania: " << czas.count() << " s\n";
- poczatek = std::chrono::high_resolution_clock::now();
- eliminacja();
- koniec = std::chrono::high_resolution_clock::now();
- czas = koniec - poczatek;
- std::cout << std::fixed << "czas czas eliminacji: " << czas.count() << " s\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement