Expert Mod 2.5K+
P: 2,851

boxfish's suggestion is a good way to do it. I have a Matrix object with a __setitem__() overload.  m0 = Matrix(7,7)


import random


for i in range(m0.rows):

for j in range(m0.cols):

m0[i,j] = random.randrange(1,7)
 >>> print m0

Row 0 = [1, 2, 5, 1, 4, 5, 1]

Row 1 = [6, 6, 4, 2, 5, 3, 6]

Row 2 = [2, 2, 4, 4, 1, 1, 5]

Row 3 = [1, 4, 5, 3, 4, 3, 4]

Row 4 = [3, 6, 6, 5, 5, 6, 4]

Row 5 = [4, 3, 6, 4, 1, 5, 2]

Row 6 = [4, 6, 5, 2, 4, 4, 4]

>>>
