I am working on an iOS word game which is built around pulling random words from a SQLite database.
So I have 1 table, Words, I pull out X random words like so:
SELECT Word FROM (SELECT Word FROM Words ORDER BY RANDOM() LIMIT @limit) ORDER BY LENGTH(Word)
Problem is that my beta users have complained it isn’t random enough. It seems to pull the same words alot of the time and some words never at all.
Is there an alternative to what I’m doing? I know SQLite’s RANDOM() probably isn’t the best. I don’t want to load all the words in memory, because there are over 3,000.
PS – my app is build in C# with MonoTouch, but I can take Objective-C (or even pseudocode) answers for sure
Maybe because you order them? You select a randomly ordered list of words, and then you do another select and order this result by word length. That second ordering might mess up your randomization. I would split this up and depending on the words you need in the game make the length a where clause, or select by length first and randomize those lists?