Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: average of the consecutive coin tosses

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121980] Re: average of the consecutive coin tosses
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 7 Oct 2011 04:52:07 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j6jobf$lv7$1@smc.vnet.net>

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