# 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. – m_goldberg Jun 23 '14 at 13:58
• want to Create 2*2 matrix consist of 2 rows and 15 columns with random integers up to 15. – Irah Idebus Jun 23 '14 at 14:01
• Not a 15x2 matrix with each element being a 2x2 random integer matrix? That is what your example looks like. – Yves Klett Jun 23 '14 at 14:01
• That is right.. – Irah Idebus Jun 23 '14 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 – Irah Idebus Jun 23 '14 at 14:05
• Please note that @m_goldbergs answers is the way to go in terms of efficiency and speed. – Yves Klett Jun 23 '14 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.. – Irah Idebus Jun 23 '14 at 14:55
• Further calculations with nested MatrixForm elements will be difficult, though. – Yves Klett Jun 23 '14 at 16:28