Famous video website Bilibili's lottery may have only 1 non-member among 10 winners, and in Wang Sicong's lottery, there may be only one non-beautiful woman among 100 winners. Even the basic gender fairness cannot be achieved. So how can we achieve a fair lottery?
As an absolute lottery loser, I spent some time studying the principles of lottery to understand why I never win. I found that achieving a fair and just lottery is not easy.
Online live streaming lotteries often use the method of screenshotting the barrage, which can create an active atmosphere but cannot reproduce the lottery results. Some bloggers use a combination of sorting the lottery range and generating a random number. For example, if there are 100 people, they will sort them in a certain way and then generate a random number between 0 and 100. The person corresponding to that number is considered the winner. However, this method cannot determine if the random number is truly random, and participants cannot verify the fairness of the lottery. Even if the organizer provides a screenshot, it cannot prove the fairness of the lottery.
Using random numbers can ensure that each participant has an equal chance of winning in the lottery. Each participant's options are equivalent, and each option has an equal chance of being selected. Using random numbers can ensure this fairness.
At the same time, using random numbers can increase the fun and excitement of the lottery. Each participant does not know if they will be chosen, which adds excitement and suspense to the lottery.
To ensure randomness during the lottery process, a high-quality random number generator is needed. A good random number generator should be unbiased, independent, uniform, and have periodicity. If the generated random numbers are not of high quality, it may result in unfair lottery results or high predictability.
We all know that computers cannot generate true random numbers, and all computer random numbers are pseudo-random. So I used the hash value of the first Bitcoin block header after a certain predetermined time point as the random number. Since I cannot mine, I cannot generate block headers, let alone manipulate the results of random number generation. The basic algorithm of the lottery uses the hash algorithm.
Here is the specific process of implementation:
- Compile the IDs of the participants.
- Determine a fixed time, such as April 22, 2023, 13:00 in the UTC+8 time zone, and take the hash value of the first Bitcoin block header after this time as the random number.
- Take the hash value of each person's ID together with this random number.
- Sort the obtained hash values and determine the winners based on the number of winners.
I don't know how to write code, so I asked ChatGPT to help me write this code.
After installing the necessary libraries, you can execute it. The participant ID can be the Bilibili UID, mobile phone number, or even a person's name. Below, I will demonstrate using QQ numbers. You can export the QQ numbers of group members using the two websites shown above.
After exporting, you will get a .txt file consisting of all QQ numbers. Then, based on the determined time, open the blockchain browser and find the block header hash value you need. Fill in this hash value and the .txt file name in the program above, and finally run the program. The first winner will be the prize winner.
The program I used will be open source, and I will post it in the comments section.