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
  • Subject: [mg122385] Re: Coin Toss Sim
  • From: James Stein <mathgroup at>
  • Date: Thu, 27 Oct 2011 06:29:51 -0400 (EDT)
  • Delivered-to:
  • References: <>

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

The reason you can get a result such as this:
    {{"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> 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