# Turning a NB into a Repeatable Script?

I am interested in "automating" the following notebook file so that I can execute it many times to generate many plots.

roots = x /. NSolve[Sum[RandomVariate[NormalDistribution[]]*x^k, {k, 0, 1000}] ==
0, x, Reals]
difs = Differences[roots]
a = Tally[difs]
ListPlot[a, AxesLabel -> {diffs, occurences}, PlotLabel -> "A Degree 1000" , PlotRange -> Full]
Export["plot.pdf", %]


Each time the code is evaluated, I of course obtain a different plot. I would like to have maybe 100 of the plots but this would be rather tedious as I have to save the plot output as a PDF individually and run the whole notebook each time. I also want to do other degrees than 1000 so I will definitely need to automate this process. I have looked into the Wolfram Script stuff, but am a bit lost/ not sure what to do. Is it possible to turn this notebook file (with 4 cells of evaluation) into a script such that I can just run it over and over with one easy command in a command line to generate multiple plots?

Any help with this issue is immensely appreciated! Thank you!

• Add another line to export plot as PDF and wrap the whole process in a Do loop? – Pinti Jun 26 '17 at 18:44
• @Pinti this just results in tons of errors though – David_Shmij Jun 26 '17 at 18:57
• I do not think you need to use Wolfram Script. You can just use Table to Map. Also, please post code, not images with code. – Anton Antonov Jun 26 '17 at 19:19
• @AntonAntonov Sorry about that , I put the code now. What do you mean by use Table to Map? Thank you for your comment! – David_Shmij Jun 26 '17 at 19:30

This generates and exports 10 images with your code:

Table[
roots =
x /. NSolve[
Sum[RandomVariate[NormalDistribution[]]*x^k, {k, 0, 1000}] == 0,
x, Reals];
difs = Differences[roots];
a = Tally[difs];
Export["/some/path/plot" <> ToString[i] <> ".pdf",
ListPlot[a, AxesLabel -> {diffs, occurences},
PlotLabel -> "A Degree 1000", PlotRange -> Full]]
, {i, 10}]