Achieve lottery idea: PHP7 add Redis realize how lucky draw every probability is not the same

Lottery needs of users, can draw three times the probability of this is 10, 15 (probability of this base in multiples of 5), you can set up their own. If other fixed probability, you can set your own hash of a Redis survive are aligned according to each lottery number and index it

  1. To a user request, Redis queue checks whether there is a user
  2. User checks the presence of the number of draw, is less than = 3, PHP generates a random number 100, if the number of times a user can draw a recording * lottery result between the probability of winning each of the base -1
    1. A user data recording lottery number lottery results
  3. Users put the lottery user queue does not exist. And the first draw. Here the default is 1 lottery number. (Can not be added after the completion of the lottery draw number, to avoid rapid repeated clicks submit, lottery number exceeded)
  4. Improve:
  5. The number of prizes set up a similar spike in the number of checks, to avoid the payment of gifts over budget.

Guess you like

Origin www.cnblogs.com/stillstep/p/11056561.html