Last active
July 29, 2020 19:46
-
-
Save ubaidh/cef8c616c25467ab176f16943a8c8428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<random> | |
#include<chrono> | |
#include<vector> | |
#include<string> | |
int main(int argc, char**agrv) { | |
auto seed = std::chrono::steady_clock::now().time_since_epoch().count(); | |
std::default_random_engine eng(seed); | |
std::cout << eng()<<std::endl; | |
std::uniform_int_distribution<int> distr(0, 10); | |
std::cout << distr(eng)<<"\n"; | |
std::uniform_real_distribution<double> distR(0, 10); | |
std::cout << distR(eng) << "\n"; | |
std::poisson_distribution<int> distP(1.0); //mean | |
std::cout << distP(eng) << "\n"; | |
std::cout << "normal distribution" << std::endl; | |
std::normal_distribution<double> distN(10.0, 6.0); | |
std::vector<int> v(20); | |
for (int i = 0; i < 800; i++) { | |
int num = distN(eng); | |
if (num >= 0 && num < 20) | |
v[num]++; | |
} | |
for (int i = 0; i < 20; i++) { | |
std::cout << i << ":" << std::string(v[i], '*') << std::endl; | |
} | |
std::cin.get(); | |
return 0; | |
} | |
//g++ -std=c++11 -o random.exe 03-random.cpp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment