LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Coin Toss Simulator

You are close but just not making the connection.  As stated before 1024 tosses of 10 coins is not the same as 1024 coins with a streak of 10.  Simple as that =).  If you want to prove your original point your program should acurately reflect the method to get there.  I.E., instead of tossing 1024 coins and looking for streak (which is 40%) toss 10 coins 1024 (or more) times!

 

New Bitmap Image.png

Message 61 of 92
(3,263 Views)

Edjsch wrote:

But that flies in the face of your previous 50% prediction, no?


Where did I predict 50%? I commented on your code, not on your algorithm. It is luck that your race condition laced code still yielded the correct 40%. 😮

0 Kudos
Message 62 of 92
(3,262 Views)

Altenbach >> Where did I predict 50%?

 

You said, "You can flip a coin on that outcome. :smileyvery-happy:" which I took to mean 50-50. No?

 

As far as my "race condition laced code" I corrected that 1 race condition that I saw (resetting the local variables to zero before the next iteration of the For loop), and got the same result. (I would bet that the LabVIEW compiler executes code before it executes loops (both within the same structure), but I'm just guessing based on experience. The compiler gurus would have to weigh in. But you are correct in that it is indeterminate and better code is to force the execution sequence the way intended and not rely on the compiler, which could change with its version.)

 

Now I'm going to study Don_Phillips' code.

 

Ed

0 Kudos
Message 63 of 92
(3,253 Views)

Don,

 

Can you down-convert your vi to version 8.5 easily and re-post? Otherwise I'll submit it for down conversion.

 

Thanks,

Ed

0 Kudos
Message 64 of 92
(3,248 Views)

Sure... 8.5 it is

 

0 Kudos
Message 65 of 92
(3,243 Views)

@Edjsch wrote:

Altenbach >> Where did I predict 50%?

 

You said, "You can flip a coin on that outcome. :smileyvery-happy:" which I took to mean 50-50. No?


I made a point quoting in that comment to ensure that it is clearly about the probability of another head after 10 consecutive heads. That's 50%.

0 Kudos
Message 66 of 92
(3,237 Views)

Ed,

 

You are still comparing apples and oranges.  The chance of the next toss being a head is still 50%  whether the previous 9 tosses are are all heads, all tails, or some combination.  That is what you are trying to prove to this person.

 

The 40% number is the chance of having at least 1 run of 10 or more heads within a string of 1024 tosses.  There is a chance that in 1024 tosses, you never even have 2 consecutive heads.  There is a chance that you have 1024 consecutive heads.  Why did you pick the number 1024 as the magic number of tosses to try to prove the 50% number?  Why didn't you pick 20 tosses, the 40%  is going to drop very low to about 1/512.  Why didn't you pick 1 billion tosses?  That 40% number is going to grow, possibly well over 50%.

 

The analysis you are doing has absolutely nothing to do with what you are trying to prove, yet you don't seem to be getting that despite what everyone is trying to tell you.

0 Kudos
Message 67 of 92
(3,235 Views)

RavensFan >> Why did you pick the number 1024 as the magic number of tosses to try to prove the 50% number?

 

I picked it because 1/(2^10) = 1/1024.

 

I was thinking that if the "expected probability" of 10 tosses of getting 10 heads is 1/1024, that, is equivalent to saying that in in infinite number of tosses, 10 (or more) heads in a row has a 50% chance of coming out for every 1024 tosses. But I think I now see what you are saying. I took another look at your 04-18-2013 01:40 PM post and you're right, it doesn't work out to 1/(2^2) but rather 1/2. So this is the apples and oranges you are talking about! Thanks.

 

Now I'll look at Don's code, which he converted to V8.5 for me. Later...

 

Ed 

Message 68 of 92
(3,218 Views)

Ed,

 

you still make a similar mistake than your friend, only the other way round 😄

As already written:

Each toss (event) is independant of previous events and their results. So stating "If i have a streak of 10 heads in a row, what is the chance to get an 11th head with the next toss?" is a complete different question than "What is the over all chance to get a streak of n (or more) 'successes' in a row in a test with m tries?"

The first question just looks on the event, even if it states previous results of events. Still, you look into an isolated event.

The second question looks only into results within a given number of trials. As explained before: If you toss a coin and don't get 'success', you make a complete new experiment with n successes within m-1 trials! So a 'fail' affects the whole experiment!

 

Let's go into this:

What is the chance of getting 10 heads in 10 trials? We concur, that this is 0.5^10 = 1/1024.

So, let's add an 11th trial. What is the chance to get 10 heads in 11 trials?

If the first toss is heads, the next 9 tosses have to be heads again. the 11th trial is not important anymore. So the chance for this is still 1/1024. But, if we get a tails in the first trial, we still got 10 trials to complete the streak! So if the next toss is heads (which is 50%), we still got a chance of 1/1024 to complete the trial. What is the overal chance for 10 heads in 11 trials?

Draw a graph with all results of consecutive results of events (aka. the heads or tails). You will see that it results in 2 cases which are success in total (10 heads in a row) vs. 2048 (2^11) possible results for all trials! So adding a new toss does not increase the chance, it leaves it the same (2/2048 = 1/1024)!

You can go on creating graphs of result-chains and count success vs. fails. You will see, that this will NOT result in 50% for 1024 tosses, but less. On the other hand, drawing graphs of this size will get very.... bulky 😄

 

hope chances are 100% now to understand,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 69 of 92
(3,168 Views)

Norbert,

 

>> you still make a similar mistake than your friend, only the other way round :smileyvery-happy:

 

No, it's not even close; it's much more subtle.

 

Anyway, I was with you almost to the end, then you lost me when you said:

 

>> So adding a new toss does not increase the chance, it leaves it the same (2/2048 = 1/1024)!

 

I disagree. Before that you said: "What is the chance of getting 10 heads in 10 trials? We concur, that this is 0.5^10 = 1/1024."

 

Great. Then you said: "What is the chance to get 10 heads in 11 trials?"

 

Of course it would be greater than 1/1024 because we've added another toss. You correctly said that if the first (of 11) tosses is a head, then we only need 9 more, and the chance of that is 1/512. But if it's a tails, then we're back to 1/1024. This is basically my point: Half the time (heads on the first toss) we got 1/512 and the other half (tails on the first toss) 1/1024. This is why I thought that the chance of getting 10 heads in a row in an infinite number of tosses averages out to 50%.

 

The fact that the simulation shows about 40% rather than 50% is rather subtle. I don't think anyone would intuitively predict this. Don't you agree?

 

Thanks for your input, though.

 

0 Kudos
Message 70 of 92
(3,150 Views)