fork(1) download
  1. #include <iostream>
  2. #include <iterator>
  3. #include <assert.h>
  4. #include <algorithm>
  5. #include <stdlib.h>
  6.  
  7. using namespace std;
  8.  
  9. bool a[100];
  10.  
  11. int random(int b, int e)
  12. {
  13. assert(b<=e);
  14. return b+((e-b)*(1.0*rand()/RAND_MAX));
  15. }
  16.  
  17. int main() {
  18. srand(clock());
  19. for(int i=0; i<10; ++i)
  20. {
  21. a[i]=true;
  22. std::swap(a[i], a[random(i+1,100)]);
  23. };
  24. cout<<endl;
  25. std::copy(a, a+100, ostream_iterator<decltype(a[0])>(cout, "\n"));
  26. return 0;
  27. }
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
1
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0