# Using one table for multiple arguments

So I want to plot two graphs (on the same plot). One which is the $\frac{\sum_{i=0}^n x_i}{n}$ and the other $\frac{\sum_{i=0}^n x_i}{n-1}$ where x is a set created by RandomInteger[{a,b},n] and then have n slowly increase. I was wondering if this would be a sort of nice convergence plot over a large interval. The problem is as seen I want all of them to use the one {n,c,d} table for their iteration but Sum wants a copy, Plot wants a copy and RandomInteger wants the length of it. How can I use one of it for all of those?

-
They will converge to (a+b)/2 ... or am I missing something? –  belisarius Apr 10 '12 at 1:53
p0[a_, b_, 1] := p0[a, b, 1] = RandomInteger[{a, b}]; p0[a_, b_, n_] := p0[a, b, n] = (p0[a, b, n - 1] (n - 1) + RandomInteger[{a, b}])/n; p1[a_, b_, n_] := p0[a, b, n] n/(n - 1); ListLinePlot[{Table[p0[0, 10, k], {k, 2, 50000}], Table[p1[0, 10, k], {k, 2, 50000}]}] –  belisarius Apr 10 '12 at 1:54

 datalistPlot[a_Integer, b_Integer, c_Integer, d_Integer, e_Integer: 1] :=
Module[{left = Mean@RandomInteger[{a, b}, c]},{
Transpose@
Table[{left=(n - 1) left/n + RandomInteger[{a, b}]/n, n left/(n - 1)}, {n, c, d, e}],
{c, d},
(a + b)/2
}]
// ListLinePlot[#[[1]],
GridLines -> {None, {{#[[3]], Directive[Red, Thick]}}},
DataRange -> #[[2]], PlotRange -> {Automatic, #[[3]] + {-1, 1}}] &


and use as

datalistPlot[list[0, 10, 10, 500, 10]


to get

-

Assuming you want each of the summations over two different randomly generated lists:

{Total@ RandomInteger[{a, b}, #]/#,
Total@ RandomInteger[{a, b}, #]/(# - 1)} & /@ Range[2, n] //
Transpose // ListLinePlot

-
Total[] might be a useful thing here. –  Guess who it is. May 4 '12 at 3:10
@J.M. Yes you are right... some pre version 5 habits showing up here :) –  image_doctor May 4 '12 at 12:20
Don't worry; you aren't alone. I haven't fully shaken off old Mathematica habits of mine as well... –  Guess who it is. May 4 '12 at 12:23
Is there any advantage of Total over Plus@@? –  celtschk May 4 '12 at 12:41
Some cursory experiments seem to suggest Total is probably faster. –  image_doctor May 4 '12 at 12:59