Did you run it just the once? I would expect avgVal to be all over the place considering the expected result is infinite and the deviation not a lot smaller.From my model about $13
I ran it 100000000 times (literally, check out the while(i<100000000) { } statement, that's C++ code for "Run this shit 100000000 times bro" as long as you're increasing i each time it goes through.)Did you run it just the once? I would expect avgVal to be all over the place considering the expected result is infinite and the deviation not a lot smaller.
expectedResult = (1/2)*1 + (1/4)*2 + (1/8)*4 + ... + (1/2^n)*2^(n-1) + ...
since (1/2^n)*2^(n-1) = (2^(n-1))/(2^n) = 1/2 expectedResult does not converge.
As to the question of whether or not a casino would run such a lottery... just imagine Loki is running the casino as a practical joke or something and that he is creating money out of thin air.
It is infinite based on statistics, that is what the sigma notation in the wiki article is telling you. That is the point of the problem... foddon is right about why all those other games are not infinite. They are programmed/designed to be non-infinte, no matter what. Which is precisely why this game, as stated, would never be run by a casino. They would do what they do withevery other gamethat has potential to be infinite: put an arbitrary cap on it. Just like they do with roulette. Now at that point the average return is easy to figure out and they would charge slightly more than that. However no one would play it, because without the possibility of infinite money such a game is frankly boring, as you noted.Theexpectedpayout, based on statistical models, is not infinite though, nor is it even very large, is my point.
Like I mentioned earlier, I'm a little concerned about the consistency of rand() (but not concerned enough to say that it's not good enough for our purposes). I ran Tuco's code essentially unmodified, and got the exact same numbers. I was interested in seeing how the averages changed over time, but wanted a little coarser scale than the commented out lines, so I made it output every time "i" went up an order of magnitude, then ran it 1,000,000,000 times. I would have added another zero and let it run overnight, but for some reason using long long ints for i and iMag caused some kind of problems that I can't even begin to diagnose.I got that. What I am saying is that if you run your code another time, your average might not be anywhere close to 13 despite the sample size. I tried to test it myself, but I forgot most of the little I knew about C, so I am not sure what I need to include for your code to compile.
Hehe, that's exactly how rand() is supposed to work, it's not fubared.A good sign rand() is fubared is that you getexactlythe same results as Tuco at the 100000000 mark even though the values are not converging.
No wonder I keep getting the same Minecraft maps!This means that if you seed it with the number 5 and call it a 1000 times it will return the same 1000 numbers. This makes it very useful for certain simulations (Because you can have a semi-random but repeatable simulation).
If you want some more random you can seed it with a different number before you start calling it. Giving it a timestamp is popular because you'll never give it that seed again:
srand (time(NULL));
Yeah, the odds of 3 heads in a row is 8:1 and it would pay out 8:5. The casino would be all over that shit. I think that to be "fair" the initial bet should be 1 dollar since both the pot and the odds of winning double with each coin flip.Not sure if you guys are understating how it works. If you pay $5 to play you'd need 3 heads in a row before you actually win anything. Odds are against that so the casino will win much more often.
But then you could never lose any money, so how is that "fair" to the casino?Yeah, the odds of 3 heads in a row is 8:1 and it would pay out 8:5. The casino would be all over that shit. I think that to be "fair" the initial bet should be 1 dollar since both the pot and the odds of winning double with each coin flip.
You're right, I forgot the part where you actually win on the tails. The casino also has risk because the payout keeps going up with consecutive heads but what they take in is static. Probably $3 would work out fairly well.But then you could never lose any money, so how is that "fair" to the casino?