Solutions will be available when this assignment is resolved, or after a few failing attempts.
Random Numbers Matrix
random module (more below) to write a function
random_matrix that returns a matrix size
n with random numbers (
m is the number of rows and
n is the number of columns).
The only restriction is that elements in the matrix CAN'T be repeated, they must be unique. Examples:
random_matrix(3, 2) [ [29, 11], [91, 85], [56, 18], ] random_matrix(4, 4) [ [29, 11, 23, 90], [91, 85, 92, 75], [56, 18, 13, 47], [65, 99, 49, 10] ]
To generate random numbers you can use the
random module. It's super simple, check the following example (or try it for yourself):
import random number = random.randint(0, 100) # A random number between 0 and 100 print(number)
test size 3x2 elements not repeated - Run Test
def test_size_3x2_elements_not_repeated(): matrix = random_matrix(3, 2) assert len(matrix) == 3 for row in matrix: assert len(row) == 2 repeated_elements =  for row in matrix: for elem in row: assert elem not in repeated_elements repeated_elements.append(elem)