this is probably a very easy question for all of you.

I have a stochastic Mathematica code (not important what it's exactly) which gives me a number at the end. Now I want Mathematica to run this code 1000 times and put all the numbers into a list.

I tried by using the command While, but it gives for all of the thousand iterations the same number back.

How can I do this?

Edit: Perhaps it's better to show you the code:

XUJ = dataRe[χFF]["Values"] + I dataIm[χFF]["Values"];
XUJB = dataRe[χBB]["Values"] + I dataIm[χBB]["Values"];
PF[W_] = Δu/(2 Pi) (1 + 2 Re[uj.XUJ]);
PB[W_] = Δu/(2 Pi) (1 + 2 Re[uj.XUJB]);
dataLR = Transpose[{Table[W, {W, -((7 π)/10) + 2 Pi/10, (7 π)/10 - 2 Pi/10, Pi/10}], 
Log[Table[PF[W], {W, -((7 π)/10) + 2 Pi/10, (7 π)/10 - 2 Pi/10, 
     W], {W, -((7 π)/10) + 2 Pi/10, (7 π)/10 - 2 Pi/10, 

Last[LinearModelFit[Re[dataLR], x, x]["BestFit"]]/x

dataRe and dataIm generate the set of random numbers. Each time I evaluate now this cell I get a different number as it should be. I'm not sure how to implement this now into the Table command.


closed as off-topic by MarcoB, m_goldberg, dr.blochwave, Öskå, LLlAMnYP Nov 28 '15 at 14:27

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." – MarcoB, m_goldberg, dr.blochwave, Öskå, LLlAMnYP
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    $\begingroup$ Probably you are storing the value to the same variable? Considering storing it an array. Use ConstantArray to pre-initialize the array for speed. It's difficult to say without MWE. $\endgroup$ – Saurav Nov 27 '15 at 16:33
  • $\begingroup$ Consider r := RandomReal[]; Table[r, {20}]. $\endgroup$ – J. M. will be back soon Nov 27 '15 at 16:42
  • 1
    $\begingroup$ results = Table[yourStochasticFunction[], {1000}] $\endgroup$ – MikeLimaOscar Nov 27 '15 at 16:43
  • $\begingroup$ The question was put on hold because it contains a simple mistake? Could someone tell me where this simple mistake is? $\endgroup$ – QuantumMechanics Nov 28 '15 at 15:40

Have a look at Table and try;

f[x_] := (x + 1)/Sin[x]
myTable = Table[f[x], {x, 1000}];

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.