Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5510

Re: average of the consecutive coin tosses

From Peter Pein <petsie@dordos.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: average of the consecutive coin tosses
Date 2011-10-07 09:10 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j6mfmn$7nd$1@smc.vnet.net> (permalink)
References <j6jobf$lv7$1@smc.vnet.net>

Show all headers | View raw


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

Hi Michael,

1.) generate the table with RandomInteger[]
2.) make use of the attribute Listable.
    Divide the Table by the Range of integers:

tr = Accumulate[RandomInteger[1, 1000]]Range[1000]^(-1);

This is approximately 3.5 as fast as your approach.

Peter

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

average of the consecutive coin tosses michael partensky <partensky@gmail.com> - 2011-10-06 08:19 +0000
  Re: average of the consecutive coin tosses Jonas <coroa@online.de> - 2011-10-07 09:01 +0000
  Re: average of the consecutive coin tosses Peter Pein <petsie@dordos.net> - 2011-10-07 09:10 +0000
  Re: average of the consecutive coin tosses Peter Pein <petsie@dordos.net> - 2011-10-07 09:11 +0000
  Re: average of the consecutive coin tosses "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-08 18:49 +0000

csiph-web