Introduction
Today's society, a wide variety of lottery activities are quite common, the basic principles of lottery and the main characteristics of randomness, but for a group within the lottery, there is a relatively balanced problem, the so-called relative equilibrium means that the probability of winning each department and its number of the total number of shares roughly equal. Based on access, combined with its built-in VBA language, through the program design to achieve the random lottery, through the algorithm research to achieve the relative balance of the lottery. This paper mainly introduces the system principle and the design of the main program.
system composition and principle
Lottery system mainly by the guest registration, ticket management, Lucky Draw, award-winning query four basic modules, registration module registration to participate in the lottery, ticket management module initialization to participate in the draw list, lottery module to achieve the lottery function, the award-winning Query Module query award results. Among them, the lottery module can realize the reward level, the total draw number, each lottery number control. The system architecture diagram is shown in Figure 1.
Figure 1 System architecture
System Initialization
Guest Registration module has included the list of people to participate in the lottery and the department, in the award management module, when the click of the initialization button through the internal program design first of the last lottery results empty, while using Rnd in the lottery before the list of people randomly generated a series of serial numbers, Prepare for the random draw in the lucky draw module [1]. The main initialization program code is as follows:
The following are the referenced contents: Docmd.setwarnings False Docmd.openquery "Delete to the prize ticket", Acnormal, Acedit Docmd.openquery "Append to the Prize Ticket", Acnormal, Acedit Docmd.setwarnings True Set QRS = Currentdb.openrecordset ("To the prize Ticket") Qrs. MoveFirst i = 1 Do-not-QRS. Eof Qrs. Edit qrs! ordinal = Int ((211-1) * Rnd) Qrs! to award number = I Qrs. Update i = i + 1 Qrs. MoveNext Loop MsgBox ("The list of prizes is initialized.") ") Qrs. Close |
The realization of lottery function
Through the lottery module to achieve the final lottery function.
Through the reward Level combo box to control the draw level, through the lottery number combo box to control the number of lottery, through the total Draw Number combo box control total draw number. When the reward grade is one or two, third prize, the lottery number and the total draw number default values are 5, 10, 10 and 10, 30, 50 respectively. The specific values of each combo box can also be controlled by up and down arrows. Draw the interface as shown in Figure 2.
Figure 2 Lottery interface
Its program design is comparatively simple, the main procedure is as follows:
The following are the referenced contents: ...... If me! award level. Value = 1 Then Total number of me!. Value = 10 End If If me! award level. Value = 2 Then Total number of me!. Value = 30 End If If me! award level. Value = 3 Then Total number of me!. Value = 50 End If forms! lottery. Q_ Lottery statistics. Requery If me! award level. Value = 1 Then me! lottery number. Value = 5 End If If me! award level. Value = 2 Or me! award level. Value = 3 Then me! lottery number. Value = 10 End If ...... |
Start the lottery by clicking the Start button, and the button title turns to stop, click again to stop the lottery, at the same time the button title into the beginning, continue to click to start the next batch of lottery, so repeatedly, until the completion of the total draw number, at this time prompted the "total lottery has arrived", if not completed the total draw number on the start of another round of draw, then Lottery limit. "
The internal lottery mainly solves two problems of randomness and relative equilibrium. System initialization in the lottery to participate in the list of randomly generated serial number, through the query "number reordering" will participate in the lottery draw list in ascending order, in order to draw the lottery in accordance with the serial number of the lottery, to achieve a random request. Relative equilibrium requirements roughly according to the percentage of the total number of people in each sector to allocate the number of winners, the system uses the total number of departments in the percentage of the lottery number by the total number of methods to roughly determine the winning numbers of each department, a number of decimal numbers through the design of the rounding process. It should be noted that the number of winners in all departments should be rounded to deal with the method may be wrong, in order to avoid this situation needs to select a department, so that its number of winners equals total draw number of other departments won the number of winners and [2]. The main program code for the Lottery module is as follows:
The following are the referenced contents: ...... N = 0 CNT = me! Electric Branch. Value + me! Electric. Value + me! Automation. Value + me! communication. Value + me! Hospital office. Value + me! retirement. Value Does while me! lottery number. Value > N and not QRS. Total number of EOF and CNT < me!. Value ' Electric Science Lottery ' Rounding to determine the number of winners in the division If me! Electrical Division. Value < ((unit1. Name count/cnt1) * me! Total quantity. Value + 0.5)) and N < me! lottery number. Total quantity of Value and CNT < me!. Value Then If QRS. Unit = "Electrical Division" and qrs! batches. Value = 0 Then me! Electric Department. Value = me! Electrical division. Value + 1 Qrs. Edit Qrs! award level. Value = me! reward level. Value qrs! batches. Value = me! lot. Value Qrs. Update n = n + 1 End If Else End If ...... ' Retirement Lottery CNT = me! Electric Branch. Value + me! Electric. Value + me! Automation. Value + me! communication. Value + me! Hospital office. Value + me! retirement. Value cnt2= me! Electric Department. Value + me! Electric. Value + me! Automation. Value + me! communication. Value + me! Hospital office. Value ' Surplus quantity allocated to retirement If me! retires. Value < Int (me! total quantity. Value–cnt2) and N < me! lottery number. Total quantity of Value and CNT < me!. Value Then If qrs22. Unit = "retired" and qrs! batches. Value = 0 Then Me! retired. Value = me! retire. Value + 1 Qrs. Edit qrs22! award level. Value = me! reward level. Value qrs22! batches. Value = me! lot. Value Qrs22. Update n = n + 1 End If Else End If ...... ' Decide whether to finish the lottery CNT = me! Electric Branch. Value + me! Electric. Value + me! Automation. Value + me! communication. Value + me! Hospital office. Value + me! retirement. Value If cnt = total number of me!. Value Then MsgBox ("The total number of lottery draws has arrived.") ") Me. Can draw. Value = 0 Else MsgBox ("Lottery limit.") ") End If ...... |
Conclusions
This system uses Access database, combined with its built-in VBA language, discusses the key problems such as system initialization, lottery's randomness and relative balance, and satisfies the requirement of lottery. The system can be applied to a variety of lottery occasions with appropriate adjustments.