Re: The Monty Hall Problem
Nope... 75% of the time is correct... Mythbusters covered this once on why it comes out the way it does....
Mythbusters Monty Hall
-tg
Re: The Monty Hall Problem
I don't know what answer Myth Busters came up with as all the video links seem to have been taken down by the copyright police. However, if it's the standard Monty Hall problem then the answer should be 66%.
The reason you are getting 75% is that your method for generating random numbers is somewhat skewed (in this particular case you'll get twice as many 1's as 0's or 2's).
There's a couple of easy fixes:
1) If using the VBMath.Rnd() method, use the formula recommended in the MSDN here which in this case would simplify to
Code:
doornum = CInt(Math.Floor(3 * Rnd()))
2) Create an instance of the Random Class. You would create only one instance at Class level (prevents sequence repetition) and use its .Next method in your function.
Code:
Public Class Whatever
Private rnGen As New Random ' at Class Level
Private Function Simulate() As Boolean 'true means a car was won; false means a goat was won
Dim Door(2) As Boolean
Dim doornum As SByte
Dim choice As SByte = 0 'initially choose the first door every time
doornum = rnGen.Next(3)
' code
End Function
End Class
Re: The Monty Hall Problem
Thanks very much Inferrd, that was exactly the problem. I replaced Math.Round(Rnd() * 2) with Int(Rnd() * 3) and it worked great. I do understand where I went wrong now - half of the real numbers between 0 and 2 round to 1, but only a quarter round to each 0 and 2.
Thanks again :D
Re: The Monty Hall Problem
Since this is .NET, you shouldn't be using Randomize and Rnd. You should scrap that in favor of the Random object. For one thing, the way you are using Randomize will cause you trouble if you were to test the program by calling Simulate in a tight loop. The issue is that Randomize will seed the random number generator with the current system time down to the second. By calling Simulate in a tight loop, you would end up calling Randomize more than once per second, which would mean that it would seed more than once with the same value, which would mean that your sequence would be exactly the same over and over and over, until the second advanced and you got a new sequence again and again.
The Random object has the same issue, of course, but if you create it a single Random object at form scope then you won't have that issue. You could also solve the problem by calling Randomize only one time, such as in Form Load, but what's the point of using Rnd, which sucks, versus the GetNext method of Random, which is far easier to get right?