Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5913 > unrolled thread
| Started by | James Stein <mathgroup@stein.org> |
|---|---|
| First post | 2011-10-27 10:34 +0000 |
| Last post | 2011-10-27 10:34 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Coin Toss Sim James Stein <mathgroup@stein.org> - 2011-10-27 10:34 +0000
| From | James Stein <mathgroup@stein.org> |
|---|---|
| Date | 2011-10-27 10:34 +0000 |
| Subject | Re: Coin Toss Sim |
| Message-ID | <j8bc3j$8ou$1@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@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}
> ]
>
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web