# Creating nested matrix using random integers

How do i create 15x2 matrix with 2x2 random integer elements?

My code only returned identical 2x2 elements:

• Please do not post images of code, but post code as text with markdown formatting. Commented Jun 23, 2014 at 13:58
• want to Create 2*2 matrix consist of 2 rows and 15 columns with random integers up to 15. Commented Jun 23, 2014 at 14:01
• Not a 15x2 matrix with each element being a 2x2 random integer matrix? That is what your example looks like. Commented Jun 23, 2014 at 14:01
• That is right.. Commented Jun 23, 2014 at 14:03

You don't really want to use ConstantArray which always populates the matrix with its first argument repeated as many times as necessary. That first argument is only evaluated once which explains your result. To get what you want, use RandomInteger directly. It can build matrices.

SeedRandom@42;
RandomInteger[14, {2, 15, 2, 2}] // MatrixForm

An inferior alternative to the direct call to RandomInteger, but quite close to your original idea:

Table[RandomInteger[{0, 100}, {2, 2}], {2}, {15}] // MatrixForm

• This is good.. Thanks Commented Jun 23, 2014 at 14:05
• Please note that @m_goldbergs answers is the way to go in terms of efficiency and speed. Commented Jun 23, 2014 at 14:08

Is this what you are looking for?

Table[MatrixForm[RandomInteger[14, {2, 2}]], {i, 2}, {j,15}] // MatrixForm

• Thanks... Now how can i find the determinant of this matrix.. Commented Jun 23, 2014 at 14:55
• Further calculations with nested MatrixForm elements will be difficult, though. Commented Jun 23, 2014 at 16:28