|
February 21, 2011, 03:55:27 PM |
|
My math might not be correct here, so if someone could correct me if I'm wrong, I'll gladly use hashes, but my problem is that they cannot be used to create an evenly distributed number within an arbitrary range.
If we assume that the hash as a whole is fairly random (which I don't think there's any evidence to doubt this, and there's probably evidence to support it), we can't use that directly to give us a random number in an arbitrary range, the way you'd do that is to take the hash modulo the number of tickets you have sold, the lower numbers would be more likely to come up (there would be a cut off point where numbers below it would be more likely to come up than the numbers above it). For example, if your hash is in the range [0,10) (I'll use a low number here for space constraints, the same thing would happen with any number), and you have six tickets sold. If you take the hash modulo the number of tickets you have, you would end up with {0, 1, 2, 3, 4, 5, 0, 1, 2, 3}. You can see that [0,3] is more likely than four or five if you randomly picked one of those (the one you pick would be equal to your hash). This does work though if the range of your hash is a multiple of the number of tickets you've sold.
While writing this though, I realized that I could probably use the hash value as input to a random number generator in the range of the number of tickets. I don't know too much about random number generators, but if someone could give me some more information on what algorithm I'd want to use for that purpose.
And then while writing that last paragraph, I came up with another solution; if I took the hash value of the first n blocks after the end of the month, where n is the smallest prime factor of the number of tickets, and added them together, I'd get an evenly distributed number in a range that is a multiple of the number of tickets sold. Is that mathematically sound?
If I did anything like that, I'd make sure to keep a list of all tickets currently sold at all times, so that anyone can verify I'm not inserting my own tickets at the end.
|