Answers for "select one random element of a vector in c++"

C++
0

select one random element of a vector in c++

vector<int> v{10,21,24,13};

int random = rand() % v.size();
int sel_elem = v[random];

cout<<"Selected Element: "<<sel_elem<<endl;
Posted by: Guest on November-12-2020

Code answers related to "select one random element of a vector in c++"

Browse Popular Code Answers by Language