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

MathGroup Archive 2011

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

Search the Archive

Re: Coin Toss Sim

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122385] Re: Coin Toss Sim
  • From: James Stein <mathgroup at stein.org>
  • Date: Thu, 27 Oct 2011 06:29:51 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201110262139.RAA00063@smc.vnet.net>

You need to brush up on the difference between Set (=) and SetDelayed (:=).

The reason you can get a result such as this:
  Input:
    {g,s}
  Output:
    {{"tail", "head", "head", "head"}, 2}
Is because:
first: the 'g' in {g,s} computes a list of random results,
then: the 's' in {g,s} computes *another* list, then counts *that* list.



On Wed, Oct 26, 2011 at 2:39 PM, pooleman133 <poolebc221 at gmail.com> wrote:

> I am new to mathematica and am trying to make a coin flipping simulation
> however mo code isn't working. When I tell it to count the number of head it
> gives me a bad count. The code I am using is listed below any help would be
> greatly appreciated.
>
> y[n_] := Block[{g, s},
>
>
>  g := RandomChoice[{"head", "tail"}, n];
>  s := Count[g, "head"];
>  {g, s}
>  ]
>
>


  • References:
  • Prev by Date: Re: Coin Toss Sim
  • Next by Date: Re: simple question about removing elements from a table
  • Previous by thread: Re: Coin Toss Sim
  • Next by thread: Re: Coin Toss Sim