• Save
  • Run All Cells
  • Clear All Output
  • Runtime
  • Download
  • Difficulty Rating

Loading Runtime

Write a function called random_matrix that accepts two arguments m and n, where m is the number of rows and n is the number of columns of a new matrix that will be generated by the function.

Use these dimensions to generate a matrix as a two-dimensional list with the indicated number of rows (# of inner lists) and columns (# of elements within each inner list).

The inner elements of the matrix should all be positive single-digit integers from 0-9 (inclusive).

Subsequent calls of the function with the same argument should generate matrices with the same dimensions but with different random integers.


Example 1

random_matrix(2,3)

returns : [[1,4,3], [6,5,0]]

Example 2

random_matrix(2,3)

returns : [[0,8,1], [9,1,1]]

Example 3

random_matrix(5,4)

returns : [[5,2,0,8], [3,1,2,2], [3,8,1,1], [4,2,0,3], [8,7,6,8]]

Reset Code