#include<iostream>
#include<vector>
#include<random>
using namespace std;
template<typename T>class RandT{
public:
RandT(T low,T high):dist{low,high}{}
T operator()(){ return dist(re);}
private:
default_random_engine re;
uniform_int_distribution<>dist;
};
int main(){
RandT<int> rnd{0,4};
vector<int>histogram(5);
for(int i=0;i!=200;++i){
++histogram[rnd()];
}
for(int i=0;i!=5;++i){
cout<<i<<'\t';
for(int j=0;j!=histogram[i];++j)
cout<<"*";
cout<<endl;
}
system("pause");
return 0;
}
F:\Codes\test>a.exe
0 ****************************************
1 ************************************
2 *********************************************
3 *************************************
4 ******************************************
请按任意键继续. . .
网友评论