MathGroup Archive 2011

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

Search the Archive

Re: Coin Toss Sim

  • To: mathgroup at
  • Subject: [mg122413] Re: Coin Toss Sim
  • From: "Dr. Wolfgang Hintze" <weh at>
  • Date: Fri, 28 Oct 2011 05:32:38 -0400 (EDT)
  • Delivered-to:
  • References: <j89v28$8e$>

"pooleman133" <poolebc221 at> schrieb im Newsbeitrag 
news:j89v28$8e$1 at
>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}
>  ]
If I avoid RandomChoice it works fine:

y[n_] := Block[{g, s},
g := Table[If[Random[] < 1/2, "head", "tail"], {n}];
s := Count[g, "head"]; {g, s}]

{{"tail", "head", "head", "head", "tail", "tail",
"tail", "head", "head", "tail"}, 3}
-- Wolfgang

  • Prev by Date: Re: runs slowly?
  • Next by Date: Which algorithm(s) does FindIntegerNullVector[]
  • Previous by thread: Re: Coin Toss Sim
  • Next by thread: Re: Coin Toss Sim