Re: average of the consecutive coin tosses
- To: mathgroup at smc.vnet.net
- Subject: [mg121942] Re: average of the consecutive coin tosses
- From: Heike Gramberg <heike.gramberg at gmail.com>
- Date: Fri, 7 Oct 2011 04:45:13 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201110060818.EAA22381@smc.vnet.net>
You could do something like tr = With[{list = RandomInteger[{0, 1}, 10000]}, Accumulate[list]/Range[Length[list]]]; On my machine this is about a factor 2.5 faster than the original code. Heike. On 6 Oct 2011, at 10:18, michael partensky wrote: > 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
- References:
- average of the consecutive coin tosses
- From: michael partensky <partensky@gmail.com>
- average of the consecutive coin tosses