# How to generate new random numbers in a Manipulate only on demand?

I was playing with a Manipulateto visually compare calculating the mean of Normal and Cauchy random data.

Manipulate[
ListLinePlot[
{
Table[Mean@Take[#, i], {i, 1000}] &[
RandomVariate[NormalDistribution[10, 1], 1000]],
Table[Mean@Take[#, i], {i, 1000}] &[
RandomVariate[CauchyDistribution[10, 1], 1000]]
},
PlotRange -> Full,
DataRange -> n,
Frame -> True,
Axes -> False
],
{n, 50, 1000}
]


The result looks nice, but there is one problem. It regenerates the random data each time I move the slider for n. Is there some way I could set it up so that is only generates new random data when the Manipulate is first evaluated and when a button is pushed?

-

DynamicModule[{randomNormal, randomCauchy, newRandomData},
Manipulate[
ListLinePlot[{Table[Mean@Take[#, i], {i, 1000}] &[randomNormal],
Table[Mean@Take[#, i], {i, 1000}] &[randomCauchy]},
PlotRange -> Full, DataRange -> n, Frame -> True,
Axes -> False], {n, 50, 1000},
Button["New random data", {randomNormal, randomCauchy} = newRandomData[]
]],
Initialization :> (
newRandomData[] :=
RandomVariate[#[10, 1], 1000] & /@ {NormalDistribution, CauchyDistribution};
{randomNormal, randomCauchy} = newRandomData[];)
]

-
Manipulate[
SeedRandom[seed];
(...),
{n, 50, 1000}, {seed, 0, 100, 1}]

-

Simple and elegant

Manipulate[
ListPlot[list, PlotRange -> {{0, n}, {0, 1}}],
{{n, 10}, 1, 20, 1},
{{list, RandomReal[1, 10]}, ControlType -> None},
Button["Generate", {ngen = n; list = RandomReal[1, ngen]}]
]

-