POV-Ray : Newsgroups : povray.off-topic : Coin game : Re: Coin game Server Time
6 Sep 2024 17:23:58 EDT (-0400)
  Re: Coin game  
From: scott
Date: 9 Jan 2009 02:50:36
Message: <496701cc$1@news.povray.org>
>> >  How did you implement it? What type of integers did you use to count 
>> > the
>> > amount of money? (Note that a 32-bit integer will overflow after only 
>> > 32
>> > tosses of the coin, which is perfectly within the realm of 
>> > possibility.)
>
>> I used 32bit and then 64bit integers, but the result was the same.
>
>  Did you at least put an assert() to check that no more than 31 (or 63)
> tosses were ever made?

It seems that the number of tosses never exceeds 16, even when running it 
1e9 times (where you would expect around 30 tosses is likely to come up).

OK I just fixed it now, I changed my head/tail generator from:

(rand()%2) == 0

to

rand() <= RAND_MAX/2

and now it seems to behave better, after 1e9 goes the maximum number of 
tosses in a row is 29, and the average winnings per go are around $14.30.

I guess that the RNG doesn't have more than 16 odd or even integers in a 
row, but it does has more than 16 either side of the mid-value.  Perhaps I 
need a better RNG to investigate further.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.