class="c++" name="code"> #include<iostream> #include<random> using namespace std; /* default_random_engine need to be static */ vector<int> errorRandomFun() { default_random_engine e; //generator random num in 0-14 uniform_int_distribution<unsigned> u(0,15); vector<int> vec; for(int i=0;i<5;i++) { int num = u(e); vec.push_back(num); cout << num << " "; } cout << endl; return vec; } vector<int> randomFun() { static default_random_engine e; //generator random num in 0-14 uniform_int_distribution<unsigned> u(0,15); vector<int> vec; for(int i=0;i<5;i++) { int num = u(e); vec.push_back(num); cout << num << " "; } cout << endl; return vec; } int main() { default_random_engine e; cout << "min:" << e.min() << ",max:" << e.max() << endl; for(int i=0;i<5;i++){ cout << e() << " "; } cout << endl; cout << "error random function:" << endl; errorRandomFun(); errorRandomFun(); cout << "right random function:" << endl; randomFun(); randomFun(); } min:1,max:2147483646 16807 282475249 1622650073 984943658 1144108930 error random function: 0 2 12 7 8 0 2 12 7 8 right random function: 0 2 12 7 8 3 0 10 10 14