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: [mg121979] Re: average of the consecutive coin tosses
  • From: Peter Pein <petsie at dordos.net>
  • Date: Fri, 7 Oct 2011 04:51:56 -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

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



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