MathGroup Archive 2011

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

Search the Archive

Re: Coin Toss Sim

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122465] Re: Coin Toss Sim
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 29 Oct 2011 07:11:34 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j89v28$8e$1@smc.vnet.net> <201110280932.FAA20605@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

Wolfgang,

No, that doesn't work, as your output shows... a list with 5 heads but a  
count of 3.

Bobby

On Fri, 28 Oct 2011 04:32:38 -0500, Dr. Wolfgang Hintze <weh at snafu.de>  
wrote:

>
> "pooleman133" <poolebc221 at gmail.com> schrieb im Newsbeitrag
> news:j89v28$8e$1 at smc.vnet.net...
>> 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}]
> y[10]
>
> {{"tail", "head", "head", "head", "tail", "tail",
> "tail", "head", "head", "tail"}, 3}
> -- Wolfgang
>
>


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Re: Strings with different Styles in a Grid
  • Next by Date: Re: Strings with different Styles in a Grid
  • Previous by thread: Re: Coin Toss Sim
  • Next by thread: Re: Coin Toss Sim