Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5481
| From | Michael Stern <nycstern@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: average of the consecutive coin tosses |
| Date | 2011-10-07 08:55 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j6mepg$7eo$1@smc.vnet.net> (permalink) |
| References | <201110060818.EAA22381@smc.vnet.net> |
Your way:
Timing[(flips = 1; (#/flips++) & /@
Accumulate[Table[RandomInteger[], {10000}]]) // N;]
{0.078, Null}
My way:
Timing[Accumulate[RandomInteger[{0, 1}, 10000]]/Range[10000] // N;]
{0.032, Null}
On 10/6/2011 4:18 AM, 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
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: average of the consecutive coin tosses Michael Stern <nycstern@gmail.com> - 2011-10-07 08:55 +0000
csiph-web