|
[Date Index]
[Thread Index]
[Author Index]
Re: Coin Toss Sim
- To: mathgroup at smc.vnet.net
- Subject: [mg122467] Re: Coin Toss Sim
- From: "Dr. Wolfgang Hintze" <weh at snafu.de>
- Date: Sat, 29 Oct 2011 07:11:56 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <j89v28$8e$1@smc.vnet.net> <j8dstg$k5b$1@smc.vnet.net>
Sorry, my solution is nonsense (five times "head" in the list, only 3
times in count).
The point is indeed the delayed evaluation for g, as many of you have
pointed out.
--- Wolfgang
"Dr. Wolfgang Hintze" <weh at snafu.de> schrieb im Newsbeitrag
news:j8dstg$k5b$1 at smc.vnet.net...
>
> "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
>
>
Prev by Date:
Re: Matematica Beginner/Student and Mysql
Next by Date:
Re: Matematica Beginner/Student and Mysql
Previous by thread:
Re: Coin Toss Sim
Next by thread:
Re: Coin Toss Sim
|