Advertisement
Naohiro19

Random test

Nov 19th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <random>
  4.  
  5.  
  6. int main()
  7. {
  8.     int matrix[3][3] = { 0 };
  9.  
  10.     // 乱数
  11.     std::random_device rnd;
  12.     std::mt19937 mt(rnd());
  13.     std::uniform_int_distribution<> dist(1, 100);
  14.  
  15.     // 乱数を配列に格納
  16.     for (int i = 0; i < 3; i++) {
  17.         for (int j = 0; j < 3; j++) {
  18.             matrix[i][j] = dist(mt);
  19.         }
  20.     }
  21.  
  22.     // 配列に格納した配列を表示
  23.     for (int i = 0; i < 3; i++) {
  24.         for (int j = 0; j < 3; j++) {
  25.             std::cout << "matrix[" << i << "][" << j << "] = " << matrix[i][j] << " ";
  26.         }
  27.         std::cout << std::endl;
  28.     }
  29.    
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement