MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: average of the consecutive coin tosses


Am 06.10.2011 10:19, schrieb michael partensky:
> Hi.
> 
> What are the better ways of doing what this guy does very inefficiently for
> the average of the consecutive coin tosses:
> 
> tr = (flips = 1; (#/flips++) & /@ Accumulate[Table[toss, {1000}]]) // N);
> 
> where
> 
> toss= RandomInteger[];
> 
> Thanks
> Michael
sorry, I forgot to mention that using machine-precision floats is a lot
faster:

Accumulate[RandomInteger[1, 1000]//N]N[Range[1000]]^-1

is ~65 times faster than the element-wise code



  • Prev by Date: Re: list equation
  • Next by Date: Re: importing data into a CDF
  • Previous by thread: Re: average of the consecutive coin tosses
  • Next by thread: Re: average of the consecutive coin tosses