SELECT SUM(Entires) FROM 'EntryDatabase' WHERE UserName = 'riggs'
OMFG! I was on cloud9. So now i could take a needless repeat loop out of a HUGE script that i was building to make the lookup table. (just a note: i think i just lost all the non-geeks) SO now my brut force method would be a little faster. Now i can make the lookup table in just under 2 hours and then i'll be ready to pick the winners. The table has been building for just over an hour now. And i've just come to the conclusion that i was STUPID. Not only do i not have to build the lookup table, i can find everthing i need to know with a very very very simple set of functions. Like above i can do a SUM on the entries, but this time use a slight variation.
SELECT SUM(Entires) FROM 'EntryDatabase' WHERE UserNumber < 12000
This would end up telling me how many entries were submitted by users 1 through 11999. So if you've read this far you might as well stick around for the ending. So there are 28 million entries in the sweepstakes. I need to pick a winner. So pick a number between 1 and 28 million. then start calling the statement above with different numbers of users. Lets say your random number pick was 12million. You'd then call:
SELECT SUM(Entires) FROM 'EntryDatabase' WHERE UserNumber < 12000
if it was HIGHER than 12million you'd pick a number lower than 12000, lets say cut it in half. so SELECT SUM(Entires) FROM 'EntryDatabase' WHERE UserNumber < 6000
and so on and so on.
What you find in the end is that you can determine the winner in under 25 calls EVERY time. That's because 2 to the 24 is just over 16million and 2 to 25 is over 33Million. You can divide 28 million in a half only 24 times before you get below a whole number. Ok, enough geek for today. I just had to write it cause Jen was getting sick of hearing it.
