Answers for "choose random elements from vector without repetition and adding to another vector c++"

0

choose random elements from vector without repetition and adding to another vector c++

#include <random>

vector <int> _myvec1{1,2,3,4,5,6};
vector <int> _myvec2{-5,-3,10,-8};

int n = 3;  //3 elements will be added
random_device rd;
mt19937 g(rd());

shuffle(_myvec2.begin(), _myvec2.end(), g);
for (int i=0; i<n; i++){
  _myvec1.push_back(_myvec2[i]);
}
Posted by: Guest on November-12-2020

Code answers related to "choose random elements from vector without repetition and adding to another vector c++"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language