import Foundation
let ROWS = 5
let COLS = 4
func fillMatrixWithRandom0and1(matrix: inout [[Int]], rows: Int, cols: Int) {
for i in 0..<rows {
for j in 0..<cols {
matrix[i][j] = Int.random(in: 0...1) // Generates either 0 or 1
}
}
}
func printMatrix(matrix: [[Int]], rows: Int, cols: Int) {
for i in 0..<rows {
for j in 0..<cols {
print(matrix[i][j], terminator: " ")
}
print()
}
}
var matrix = Array(repeating: Array(repeating: 0, count: COLS), count: ROWS)
fillMatrixWithRandom0and1(matrix: &matrix, rows: ROWS, cols: COLS)
printMatrix(matrix: matrix, rows: ROWS, cols: COLS)
/*
run:
0 0 0 1
1 0 1 1
0 1 1 0
1 1 1 0
1 1 0 1
*/