# Variable Definitions and Random Numbers [closed]

I have currently created the following matrix:

m={{RandomReal[{0,1}],RandomReal[{0,1}]},{RandomReal[{0,1}],RandomReal[{0,1}]}}


In other words, a $2 \times 2$ matrix where the entries are real numbers. However, when I try to set $m$ to be a variable (to use it later to compute, say eigenvalues or eigenvectors), when I type m again, I obtain a different matrix than the one first obtained. I'm guessing that this is due to the fact that typing m will compute the matrix with other random reals. However, is there a way to store the matrix that is first obtained?

Say if m outputs the matrix {{1,2},{3,4}}, how can I fix this matrix for later use without obtaining a new one? Thank you for your help.

## closed as off-topic by ciao, MarcoB, Bob Hanlon, m_goldberg, Mr.Wizard♦Aug 9 '15 at 5:50

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – ciao, MarcoB, Bob Hanlon, m_goldberg, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.

As long as you use Set (m =) rather than SetDelayed (m :=) the matrix will not be given new values unless you reevaluate the definition of m.

SeedRandom[1];

Clear[m]

m = RandomReal[{0, 1}, {2, 2}]


{{0.817389, 0.11142}, {0.789526, 0.187803}}

m


{{0.817389, 0.11142}, {0.789526, 0.187803}}

m


{{0.817389, 0.11142}, {0.789526, 0.187803}}

m has a fixed value. Compare with

SeedRandom[1];

Clear[m]

m := RandomReal[{0, 1}, {2, 2}]

m


{{0.817389, 0.11142}, {0.789526, 0.187803}}

m


{{0.241361, 0.0657388}, {0.542247, 0.231155}}

• Thank you! Are the lines of code SeedRandom[1] and Clear[m] required? Or they are just for "cleaning" purposes? – hoyast Aug 9 '15 at 4:07
• They are not required. Using SeedRandom ensures that you can exactly repeat the same results if you reevaluate the notebook. This can help in troubleshooting with random numbers. – Bob Hanlon Aug 9 '15 at 4:18