fork(3) download
  1. #include <iostream>
  2. #include <random>
  3. #include <vector>
  4. int main() {
  5. using namespace std;
  6. int const LARGURA = 10;
  7. int const ALTURA = 5;
  8.  
  9. mt19937 gen(666); // gerador de números aleatórios mersenne twister
  10. uniform_int_distribution<> dis(0, 1); //distribuição linear entre 0 e 1
  11.  
  12. vector<vector<int>> M;
  13. M.resize(ALTURA);
  14. for(auto & linha : M)
  15. {
  16. linha.resize(LARGURA);
  17. for(auto & valor: linha)
  18. {
  19. valor = dis(gen); //sorteia
  20. cout << valor << ' ';
  21. }
  22. cout << endl;
  23. }
  24. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 0 1 0 1 0 1 1 1 0 
0 0 0 0 0 0 0 0 1 0 
0 1 1 1 0 0 1 0 0 0 
1 1 0 1 0 1 0 1 0 1 
0 0 1 1 0 0 0 1 1 0