fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <random>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int p=10, t=3;
  10. std::vector<int> v(p,0);
  11. for(int i=0;i<t;i++) //better way?
  12. v[i] = 1;
  13. std::random_device rd;
  14. std::mt19937 g(rd());
  15. std::shuffle(std::begin(v), std::end(v), g);
  16. for(int i=0;i<v.size();i++)
  17. cout<<v[i]<<" ";
  18. return 0;
  19. }
Success #stdin #stdout 0s 3416KB
stdin
Standard input is empty
stdout
0 0 0 1 0 1 0 0 0 1