--- In [email protected], "jasonkatzbrown" <[EMAIL PROTECTED]> wrote: > > > Related question: are the tiles drawn truly randomly? > > I'm surprised you would ask, even out of jest, but tiles are drawn as > pseudo-randomly as they need to be. If you want to further > investigate, all tile drawing goes through this one function that > draws one letter from the bag: > > [bag.cpp] > > Letter Bag::pluck() > { > return erase(DataManager::self()->randomNumber() % m_tiles.size ()); > } > > Which uses: > > [datamanager.cpp] > > int DataManager::randomNumber() > { > return rand(); > } > > This is called when quackle starts up: > > void DataManager::seedRandomNumbers(unsigned int seed) > { > srand(seed); > } > > Indeed, two quackle instances started at the same millisecond might > exhibit similar tile drawing, but aside from that, the tiles are > plenty random.
Jason, I hate to rain on your parade, but the C standard library function rand() is not really as good as you need it to be. It uses a multiplicative congruential generator, which means that the results are cyclic modulo N for any value of N that is relatively prime to the multiplier. Now, in your usage you will draw from a pool of size 100, then 99, and so on, so there is no fixed N that allows you to easily see the cyclic behavior. The non-randomness is disguised a bit. But you can find the issues. For instance, the value of rand() alternates between odd and even, so on the first 7 draws of the game you sample from bag size 100, 98, 96, and 94. All of those draws will come from slots having the same parity. I recommend the KISS random generator, which uses only 128 bits of state, provides a 32-bit result and passes all tests of randomness. You can find a reference here: http://www.math.niu.edu/~rusin/known- math/99/RNG Brian
