Lottery drawing method, device and equipment

By obtaining the probability array from the cache database and generating random numbers to determine the prize type, combining atomic operations to remove prize instances and dynamically updating the probability array, the problem of insufficient prize inventory perception in traditional lottery systems is solved, and the accuracy of the lottery as well as the stability and efficiency in high-concurrency scenarios are improved.

CN120807041APending Publication Date: 2025-10-17ABC FINANCIAL TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511024492.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-24
Publication Date
2025-10-17

AI Technical Summary

Technical Problem

Traditional lottery systems lack the ability to perceive prize inventory in real time, resulting in "empty inventory" phenomena and insufficient stability in high-concurrency scenarios. They also have high operation and maintenance costs and are unable to support instantaneous high-concurrency business needs.

Method used

By obtaining the probability array from the target cache database and generating a random number, the prize type is determined based on the random number, and the prize instance is removed through atomic operations. The probability array is dynamically updated to ensure real-time perception of the prize inventory and stability in high-concurrency scenarios.

Benefits of technology

It improves the accuracy of lottery results and user experience, enhances throughput and response efficiency in high-concurrency scenarios, and reduces operation and maintenance costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120807041A_ABST
    Figure CN120807041A_ABST
Patent Text Reader

Abstract

The invention discloses a lottery drawing method, device and equipment. In the scheme, in response to a lottery drawing request of a user, a probability array is acquired from a target cache database, and a random number is generated based on the probability array. And determining a target prize type according to the sub-interval in which the random number falls. And removing the first prize instance from a prize instance list corresponding to the target prize type stored in the target cache database through atomic operation. If the removal is successful, issuing the first prize instance to the user; and if the removal fails, returning first information indicating that the user does not draw the prize to the user, reconstructing a probability array based on the draw probability of the prize type of which the current remaining quantity is greater than zero, and updating the reconstructed probability array to the target cache database. According to the scheme, the problem of'evacuation 'is avoided by dynamically updating the probability array, lock waiting is avoided through atomic operation, accurate prize issuing is ensured, the stability and user experience of lottery drawing in a high-concurrency scene are improved, and the operation and maintenance cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of data processing, in particular to a lottery method, device and equipment. BACKGROUND

[0002] With the rapid development of digital business, lottery activities as a core means of user motivation are widely used in various Internet products. The traditional lottery system relies on a pre-set static probability model to distribute prizes, which has exposed significant defects in actual operation. Specifically, the traditional lottery method lacks real-time awareness of prize inventory, and when some prizes are depleted, it still calculates the winning result according to the initial probability, resulting in the "empty" phenomenon of users winning out-of-stock prizes, which seriously affects user experience and activity credibility. On the other hand, the stability of the traditional lottery method is insufficient in high-concurrency scenarios, and when a large number of users request lottery at the same time, resource competition can easily cause problems such as prize over-issuance (such as the issuance quantity exceeding the actual inventory) or repeated issuance (such as the same coupon code being assigned to multiple users).

[0003] In the prior art, although artificial intervention can reset the probability of out-of-stock prizes or introduce a distributed lock to address the above problems, artificial intervention has the defects of high operation and maintenance cost and strategy adjustment lag; while the distributed lock scheme significantly reduces the system throughput and response speed due to the locking operation, and is difficult to support instantaneous high-concurrency business requirements. SUMMARY

[0004] Based on the above problems, the present application provides a lottery method, device and equipment, which aims to improve the real-time awareness of prize inventory in the lottery process to avoid the "empty" phenomenon, while enhancing the stability and response efficiency of the lottery in high-concurrency scenarios, ensuring the accuracy of prize issuance and user experience on the basis of reducing operation and maintenance cost.

[0005] The embodiments of the present application disclose the following technical solutions:

[0006] The first aspect of the present application provides a lottery method, which comprises:

[0007] In response to a user lottery request, a probability array is obtained from a target cache database, and a random number is generated within the total interval range delimited by the first element and the last element of the probability array; the target cache database stores a probability array and a prize instance list corresponding to multiple prize types; the number of prize instances in the prize instance list indicates the remaining quantity of the prize type; the first element of the probability array is 0, and the subsequent elements are the cumulative values of the winning probabilities of the prize types with a remaining quantity greater than zero;

[0008] A target prize type is determined according to the sub-interval composed of adjacent elements of the probability array into which the random number falls;

[0009] remove a first prize instance from the list of prize instances corresponding to the target prize type stored in the target cache database through atomic operation;

[0010] if the removal is successful, issue the first prize instance to the user;

[0011] if the removal fails, return first information to the user, and reconstruct a probability array based on the winning probability of the prize type with a current remaining quantity greater than zero, and update the reconstructed probability array to the target cache database; the first information indicates that the user does not win a prize.

[0012] In an optional implementation, after the first prize instance is issued to the user, the prize drawing method further includes:

[0013] determining whether the number of prize instances in the list of prize instances corresponding to the target prize type is equal to 0;

[0014] in a case where the number of prize instances is equal to 0, reconstructing a probability array based on the winning probability of the prize type with a current remaining quantity greater than zero, and updating the reconstructed probability array to the target cache database.

[0015] In an optional implementation, the target cache database further stores a total remaining quantity of prizes, and before the probability array is acquired from the target cache database, the prize drawing method further includes:

[0016] acquiring the total remaining quantity of prizes;

[0017] determining whether the total remaining quantity of prizes is greater than 0;

[0018] in a case where the total remaining quantity of prizes is not greater than 0, returning second information to the user, and terminating the current prize drawing process; the second information indicates that the current prize drawing has ended;

[0019] in a case where the total remaining quantity of prizes is greater than 0, performing the step of acquiring the probability array from the target cache database.

[0020] In an optional implementation, after the first prize instance is issued to the user, the prize drawing method further includes:

[0021] updating the total remaining quantity of prizes stored in the target cache database.

[0022] In an optional implementation, the target cache database is constructed in the following manner:

[0023] store basic data of the target lottery event into a target data table, the basic data including a total remaining number of prizes, winning probabilities of a plurality of prize types, remaining numbers of the plurality of prize types, and prize instances corresponding to the plurality of prize types; the number of prize instances corresponding to a prize type is the remaining number of the prize type;

[0024] based on the basic data in the target data table, preheat data of the target cache database, including:

[0025] store the total remaining number of prizes into the target cache database;

[0026] based on the remaining numbers and winning probabilities of the plurality of prize types stored in the target data table, construct a probability array, and store the probability array into the target cache database;

[0027] create a corresponding prize instance list for each prize type in the target cache database, and store all prize instances corresponding to the prize type into the corresponding prize instance list.

[0028] In an optional implementation, the constructing of the probability array based on the remaining numbers and winning probabilities of the plurality of prize types stored in the target data table includes:

[0029] initialize a first element of the probability array as 0;

[0030] traverse all prize types with a remaining number greater than zero in the target data table;

[0031] for each prize type in the traversal, accumulate the winning probability of the prize type and a last element of the probability array to obtain an accumulated result;

[0032] add the accumulated result as a new element to the end of the probability array until the traversal of all prize types with a remaining number greater than zero is completed.

[0033] In an optional implementation, before the responding to the user lottery request, the lottery method further includes:

[0034] perform identity verification on a user who initiates the lottery request;

[0035] if the verification result is that the user belongs to a preset risk user group, reject the lottery request of the user;

[0036] if the verification result is that the user does not belong to the preset risk user group, execute the step of responding to the user lottery request.

[0037] In an optional implementation manner, the target cache database is a Redis database, and the prize instance list is a Redis list structure; each element in the Redis list structure is a prize instance.

[0038] The second aspect of the present application provides a prize drawing device, which comprises:

[0039] The prize drawing request response module is configured to, in response to a prize drawing request of a user, acquire a probability array from a target cache database, and generate a random number within a total interval range delimited by a first element and a last element of the probability array; the target cache database stores a probability array and prize instance lists corresponding to multiple prize types; the number of prize instances in the prize instance list indicates the remaining number of the prize type; the first element of the probability array is 0, and the subsequent elements are the cumulative values of the winning probabilities of the prize types with the remaining number greater than zero;

[0040] The prize type determination module is configured to determine a target prize type according to a sub-interval, in which the random number falls, which is composed of adjacent elements of the probability array;

[0041] The prize instance removal module is configured to remove a first prize instance from the prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation;

[0042] The prize instance issuance module is configured to, if the removal is successful, issue the first prize instance to the user;

[0043] The probability array reconstruction module is configured to, if the removal fails, return first information to the user, and reconstruct a probability array based on the winning probabilities of the prize types with the remaining number greater than zero, and update the reconstructed probability array to the target cache database; the first information indicates that the user does not draw a prize.

[0044] The third aspect of the present application provides a prize drawing device, which comprises a processor and a memory:

[0045] The memory is configured to store program code and transmit the program code to the processor;

[0046] The processor is configured to execute the steps of the prize drawing method introduced in any implementation manner of the first aspect according to the instructions in the program code.

[0047] Compared with the prior art, the present application has the following beneficial effects:

[0048] In the technical solution of the present application, first, in response to a user's prize draw request, a probability array is obtained from a target cache database, and a random number is generated within the total interval range delimited by the first element and the last element of the probability array, wherein the target cache database stores a probability array and a prize instance list corresponding to multiple prize types. Then, the target prize type is determined according to the sub-interval composed of adjacent elements of the probability array into which the random number falls. Thereafter, the first prize instance is removed from the prize instance list corresponding to the target prize type stored in the target cache database through atomic operation. If the removal is successful, the first prize instance is issued to the user; if the removal fails, the first information indicating that the user has not drawn a prize is returned to the user, and the probability array is reconstructed based on the draw probability of the prize type with a current remaining quantity greater than zero, and the reconstructed probability array is updated to the target cache database. It can be seen that in the technical solution of the present application, through the mechanism of dynamically updating the probability array, the "empty drawing" problem that the prize may still be selected in the traditional prize draw system after the prize is drawn out is solved. When a certain type of prize fails to be removed (there is no remaining), the probability array is immediately reconstructed based on the remaining valid prizes, ensuring that subsequent prize draw calculations are only for prize types that can be issued, improving the accuracy of the prize draw result and the user experience. At the same time, through the removal method of atomic operation, the waiting and retry problem under the distributed lock mechanism is avoided, which not only ensures that the prize instances will not be repeatedly issued and will not exceed the initial inventory, but also significantly improves the throughput of the system in a high-concurrency scenario, solving the response delay problem caused by the traditional lock mechanism. The stability and response efficiency of the prize draw in a high-concurrency scenario are enhanced, and on the basis of reducing the operation and maintenance cost, the accuracy of prize issuance and user experience are ensured. BRIEF DESCRIPTION OF DRAWINGS

[0049] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0050] Figure 1 A prize draw method flowchart provided by an embodiment of the present application;

[0051] Figure 2 A structure schematic diagram of a prize draw device provided by an embodiment of the present application. DETAILED DESCRIPTION

[0052] As described above, the current lottery method lacks real-time awareness of the prize inventory, and when some prizes are depleted, the initial probability calculation is still used, resulting in the "empty" phenomenon of users winning out-of-stock prizes, which seriously affects user experience and activity credibility. At the same time, in a high-concurrency scenario, the stability of the traditional lottery method is insufficient, and when a large number of users request lottery at the same time, resource competition can easily cause prize over-issuance (such as the number of issued prizes exceeding the actual inventory) or repeated issuance (such as the same coupon code being assigned to multiple users). In the prior art, although manual intervention can reset the probability of out-of-stock prizes or introduce a distributed lock to address the above problems, manual intervention has the defects of high operation and maintenance cost and strategy adjustment lag; while the distributed lock scheme significantly reduces the system throughput and response speed due to the locking operation, and is difficult to support instantaneous high-concurrency business requirements.

[0053] The inventors have proposed a lottery method, device and equipment.

[0054] First, in response to a user lottery request, a probability array is obtained from a target cache database, and a random number is generated within the total interval range defined by the first element and the last element of the probability array, wherein the target cache database stores a probability array and a prize instance list corresponding to multiple prize types. Next, the target prize type is determined according to the sub-interval in which the random number falls, which is composed of adjacent elements of the probability array. Then, the first prize instance is removed from the prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation. If the removal is successful, the first prize instance is issued to the user; if the removal fails, the first information indicating that the user has not won a prize is returned to the user, and the probability array is reconstructed based on the winning probability of the prize type with a current remaining quantity greater than zero, and the reconstructed probability array is updated to the target cache database.

[0055] Through the mechanism of dynamically updating the probability array, the "empty" problem of traditional lottery systems in which prizes are still selected after running out is solved. When a certain type of prize fails to be removed (there is no remaining quantity), the probability array is immediately reconstructed based on the remaining valid prizes, ensuring that subsequent lottery calculations are only for prize types that can be issued, improving the accuracy of lottery results and user experience. At the same time, through the removal method of atomic operation, the waiting and retry problem under the distributed lock mechanism is avoided, which not only ensures that prize instances are not repeatedly issued and do not exceed the initial inventory, but also significantly improves the throughput of the system in a high-concurrency scenario, solving the response delay problem caused by the traditional lock mechanism. The stability and response efficiency of the lottery in a high-concurrency scenario are enhanced, and on the basis of reducing operation and maintenance costs, the accuracy of prize issuance and user experience are guaranteed.

[0056] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application, so that those skilled in the art can better understand the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of the present application.

[0057] Referring to Figure 1 , the figure is a flow chart of a lottery method provided by an embodiment of the present application. As shown in the figure, the method comprises the following steps: Figure 1

[0058] S101, in response to a user lottery request, obtaining a probability array from a target cache database, and generating a random number within a total interval range delimited by the first element and the last element of the probability array.

[0059] In the embodiments of the present application, the target cache database refers to a cache database supporting high-concurrency read and write and based on memory, for example, a Redis database.

[0060] The target cache database stores a probability array and a prize instance list corresponding to a plurality of prize types. The prize instance list stores prize instances, and the number of prize instances stored in the prize instance list indicates the remaining number of the prize type.

[0061] In the embodiments of the present application, the prize instance refers to a specific, distributable single prize object under a certain prize type, which is the actual carrier of the prize and contains information that can be directly used by the user. The specific form of the prize instance includes but is not limited to coupon codes of coupons, exchange codes of physical prizes, etc. Each prize instance has a unique identifier and is associated with attributes such as the prize type to which it belongs and the validity period. For example, a prize type in a lottery activity is "5-yuan coupon", and the remaining number of the prize type is 2, then the prize instance list corresponding to the prize type stores 2 corresponding prize instances, i.e. specific coupon codes "COUPON001" and "COUPON002".

[0062] The prize instance list refers to an ordered list storing prize instances, for example, a list structure.

[0063] ​The probability array refers to an ordered array formed by accumulatively calculating the winning probabilities of the prize types with a remaining quantity greater than zero. The first element of the probability array is fixed as 0, and the subsequent elements are accumulative values of the winning probabilities of the prize types with a remaining quantity greater than zero. For example, in a certain lottery activity, the prize types with a remaining quantity greater than zero include prize type A, prize type B, prize type C, and prize type D, and the winning probabilities of the prize types are 0.15, 0.35, 0.4, and 0.1, respectively. Therefore, the probability array is [0, 0.15, 0.5, 0.9, 1].

[0064] In the embodiments of the present application, before the lottery activity starts, the target cache database is pre-filled with data, and the probability array and the prize instance list are stored in the target cache database. When the user initiates a lottery request, the stored probability array is obtained from the target cache database.

[0065] After obtaining the probability array, a total interval range closed on the left and open on the right is determined based on the first element and the last element of the probability array. For example, the probability array is [0, 0.15, 0.5, 0.9, 1], the first element is 0, and the last element is 1. The determined total interval range is [0, 1).

[0066] A random number is generated in the total interval range. The random number can be generated by using a random number generation tool provided by a programming language, such as the ThreadLocalRandom.nextDouble() method in Java or the Random.uniform() function in Python. Alternatively, a random number generator can be used to generate the random number, and the specific random number generation method is not limited herein.

[0067] The embodiments of the present application quickly obtain the probability array through the target cache database, and generate a random number in the total interval of the probability array, which provides a random basis for determining the target prize type based on the probability distribution, and ensures the randomness and fairness of the lottery process.

[0068] S102, determining the target prize type according to the sub-interval formed by the adjacent elements of the probability array, in which the random number falls.

[0069] In the embodiments of the present application, the target prize type refers to the specific prize type that the user can obtain in this lottery request.

[0070] The sub-interval refers to a left-closed right-open interval defined by two adjacent elements in the probability array obtained in the foregoing step, and each sub-interval uniquely corresponds to a prize type with a remaining quantity greater than zero. For example, the sub-intervals of the probability array [0, 0.15, 0.5, 0.9, 1] include [0, 0.15) corresponding to prize type A, [0.15, 0.5) corresponding to prize type B, [0.5, 0.9) corresponding to prize type C, and [0.9, 1) corresponding to prize type D.

[0071] In the embodiment of the present application, the probability array is traversed to determine the sub-interval in which the random number generated in step S101 falls. If the random number is greater than or equal to the i-th element of the probability array and less than the i+1-th element, then the prize type corresponding to the sub-interval is the target prize type.

[0072] In an example implementation, the random number is 0.45, which falls into the sub-interval [0.15, 0.5) corresponding to prize type B, and the target prize type is prize type B.

[0073] The embodiment of the present application converts the random number into a specific target prize type through the mapping relationship between the sub-interval and the prize type, and realizes the prize drawing logic based on the preset probability. At the same time, since the probability array only includes prize types with a remaining quantity greater than zero, invalid calculation of the prizes that have been drawn out is avoided, and the prize drawing efficiency is improved.

[0074] S103, removing the first prize instance from the prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation.

[0075] The atomic operation refers to an operation that cannot be interrupted, which can ensure the consistency of data processing in a high-concurrency scenario, that is, the operation on the same resource at the same time can only be executed by one request, and data errors caused by simultaneous intervention of multiple requests will not occur.

[0076] In the embodiment of the present application, the atomic operation can realize the safe acquisition of the prize instance by means of the characteristics of the target cache database.

[0077] In an optional implementation, the target database is a Redis database, and the prize instance list is a Redis list structure. Each element in the Redis list structure is a prize instance.

[0078] The lpop command of Redis can be used to remove the first prize instance from the Redis list structure corresponding to the target prize type, and the execution process of the command has atomicity, that is, even if a large number of users simultaneously request to draw the prize type, the lpop operation can ensure that each prize instance can only be successfully acquired by one user.

[0079] Embodiments of the present application ensure that each prize instance can only be obtained by one user in a high-concurrency scenario through the atomic operation feature of Redis list, avoiding the problem of repeated or excessive prize issuance. Meanwhile, the efficient execution of the lpop command ensures the rapidity of the prize drawing process, improving user experience.

[0080] S104, judging whether the removal is successful.

[0081] In embodiments of the present application, removal success refers to the successful obtaining of a prize instance from the prize instance list in the previous step; removal failure refers to the prize instance list being empty (no prize instance can be removed), i.e., the prize type has been drawn out.

[0082] In an example implementation, if the lpop command returns a non-empty result (such as “COUPON001”), the removal is successful; if the lpop command returns empty, the removal fails.

[0083] In embodiments of the present application, if the removal is successful, step S105 is entered; if the removal fails, step S106 is entered.

[0084] S105, issuing the first prize instance to the user.

[0085] In embodiments of the present application, if the removal is successful, the prize instance is issued to the user (such as displaying the coupon code), and the issuance information is recorded.

[0086] S106, returning first information to the user, and reconstructing a probability array based on the drawing probability of the prize type with a current remaining quantity greater than zero, and updating the reconstructed probability array to the target cache database.

[0087] In embodiments of the present application, if the removal fails, the first information is returned to the user, indicating that the user has not drawn a prize. For example, the information “No prize drawn this time, try again!” is returned to the user.

[0088] Meanwhile, a probability array is reconstructed based on the drawing probability of the prize type with a current remaining quantity greater than zero, and the reconstructed probability array is updated to the target cache database.

[0089] In an example implementation, the probability array stored in the target cache database is [0, 0.15, 0.5, 0.9, 1], corresponding to the winning probabilities 0.15, 0.35, 0.4, and 0.1 of the prize types A, B, C, and D respectively. After determining that the target prize type drawn by the user is prize type A through the foregoing prize drawing method, the first prize instance is removed from the prize instance list corresponding to prize type A stored in the target cache database through atomic operation, but the removal fails, indicating that prize type A has been emptied at this time, and the current remaining prize types with a quantity greater than zero are prize types B, C, and D. At this time, the first information of "no prize is drawn this time, keep trying!" is returned to the user, and the probability array is reconstructed based on the winning probabilities 0.35, 0.4, and 0.1 of prize types B, C, and D and is updated to the target cache database. The reconstructed probability array is [0, 0.35, 0.75, 0.85]. When responding to the next user prize drawing request, the prize drawing operation is performed based on the updated probability array.

[0090] The failure processing flow in the embodiments of the present application ensures that subsequent prize drawing no longer calculates the empty prize type by dynamically updating the probability array.

[0091] The embodiments of the present application solve the "emptying" problem that a prize may still be calculated to be selected after the prize is drawn out in the traditional prize drawing system through the mechanism of dynamically updating the probability array. When a certain type of prize is removed due to failure (no remaining), the probability array is immediately reconstructed based on the remaining valid prizes, ensuring that subsequent prize drawing calculations are only performed on the prize types that can be delivered, improving the accuracy of the prize drawing result and the user experience. At the same time, through the removal method of atomic operation, the waiting retry problem under the distributed lock mechanism is avoided, which not only ensures that the prize instances will not be repeatedly delivered and will not exceed the initial inventory, but also significantly improves the throughput of the system in a high-concurrency scenario, solving the response delay problem caused by the traditional lock mechanism. The stability and response efficiency of the prize drawing in a high-concurrency scenario are enhanced, and on the basis of reducing the operation and maintenance cost, the accuracy of prize delivery and user experience are guaranteed.

[0092] Optionally, after step S105, the prize drawing method further includes the following steps:

[0093] determining whether the number of prize instances in the prize instance list corresponding to the target prize type is equal to 0.

[0094] In the case where the number of prize instances is equal to 0, reconstructing a probability array based on the winning probabilities of the prize types with a quantity greater than zero, and updating the reconstructed probability array to the target cache database.

[0095] In an example implementation, after the prize instance is issued, the length of the Redis list corresponding to the target prize type can be queried by calling the llen command: if the length is 0, it means that there is no remaining prize instance of this prize type, then the probability array is reconstructed and updated to Redis by the set command.

[0096] The embodiment of the present application aims at the scenario that the target prize type has just been drawn out, triggers the probability array update in time, avoids the calculation of the prize type that has been drawn out in the subsequent draw, and ensures the accuracy of the probability calculation. At the same time, by checking and updating immediately after the prize is issued, the possibility of invalid probability calculation is reduced, and the response efficiency of the draw is improved.

[0097] Optionally, the target cache database also stores the total remaining number of prizes, and before obtaining the probability array from the target cache database, the draw method further includes the following steps:

[0098] Step 1, obtaining the total remaining number of prizes.

[0099] In an example implementation, after responding to the user's draw request, the total remaining number of prizes can be obtained from the Redis database by the get command.

[0100] Step 2, judging whether the total remaining number of prizes is greater than 0.

[0101] In the embodiment of the present application, if the total remaining number of prizes is not greater than 0, step 3 is entered; if the total remaining number of prizes is greater than 0, step 4 is entered.

[0102] Step 3, returning the second information to the user and terminating the draw process.

[0103] In the embodiment of the present application, if the total remaining number of prizes is not greater than 0, i.e. the prize types of the current draw activity are all drawn out, the second information is returned to the user and the draw process is terminated, and the second information is an information prompt indicating that the current draw has ended. For example, the user is returned “the current draw activity has ended, looking forward to your next participation!”.

[0104] Step 4, performing the draw steps of S101-S106.

[0105] In the embodiment of the present application, if the total remaining number of prizes is greater than 0, i.e. there are prize types that have not been drawn in the current draw activity, the draw method provided in the foregoing embodiments is executed normally.

[0106] This embodiment of the application pre-determines the total number of remaining prizes and directly terminates the process when all prizes have been drawn. This avoids subsequent invalid operations such as probability calculation and instance removal, reducing resource consumption. At the same time, it quickly feedbacks results to users, improving response speed in high-concurrency scenarios.

[0107] Optionally, in order to ensure the real-time accuracy of the total remaining number of prizes and provide a reliable basis for judging subsequent user lottery requests, after step S105, the lottery method further includes the following steps:

[0108] Update the total remaining number of prizes stored in the target cache database, that is, reduce the total remaining number of prizes by 1.

[0109] In an optional implementation, the target cache database is constructed by the following steps:

[0110] Step 1: Store the basic data of the target lottery activity into the target data table.

[0111] In an embodiment of the present application, the basic data is data related to the target lottery activity, for example, lottery activity configuration information such as lottery activity ID, lottery activity name, activity start time, activity end time, prize configuration information such as prize ID, prize name, prize type, initial total number of prizes, remaining number of prizes, prize status, prize detail configuration information such as prize detail ID, belonging prize ID, coupon code, validity start time, validity end time, lottery activity prize configuration information such as probability of winning.

[0112] The target data table refers to the relational database table (such as the table structure in MySQL, Oracle, and other databases) used to persistently store all basic data of the lottery activity. It is the authoritative data source for the entire lottery system and is used to ensure the persistence, integrity, and traceability of the data.

[0113] In this embodiment of the present application, basic data includes, but is not limited to, the total number of prizes remaining, the probability of winning various prize types, the number of prizes remaining for various prize types, and the prize instances corresponding to various prize types. The number of prize instances corresponding to a prize type is the number of prize instances remaining for that prize type. Basic data can be pre-written to a target data table via a data output interface, serving as a source for subsequent cache preheating.

[0114] Step 2: Preheat the target cache database based on the basic data in the target data table.

[0115] Specifically, the remaining number of prizes is stored in the target cache database. Based on the remaining number and the winning probability of each prize type stored in the target data table, a probability array is constructed and stored in the target cache database. For each prize type, a corresponding prize instance list is created in the target cache database, and all prize instances corresponding to the prize type are stored in the corresponding prize instance list.

[0116] The application embodiments achieve double protection of the prize drawing data through the target data table and the cache preheating layered storage mode: the target data table serves as an authoritative data source, guarantees data persistence and traceability, and provides a check and recovery basis for cache data. The cache preheating loads high-frequency data (total remaining number, probability array, and prize instance) into the target cache database in advance, greatly reduces access delay by using the memory characteristics, and avoids a surge in database pressure at the beginning of the activity. At the same time, the pre-constructed probability array reduces real-time calculation overhead, and the structured prize instance list lays a foundation for atomic operation distribution, thereby reducing high-concurrency data competition from the source.

[0117] Optionally, the specific steps of constructing the probability array based on the remaining number and the winning probability of each prize type stored in the target data table include:

[0118] The first element of the probability array is initialized to 0. All prize types with a remaining number greater than zero in the target data table are traversed. For each prize type traversed, the winning probability of the prize type is accumulated with the last element of the probability array to obtain an accumulation result. The accumulation result is added as a new element to the end of the probability array until the traversal of all prize types with a remaining number greater than zero is completed.

[0119] Optionally, in order to intercept risk users and avoid malicious occupation of prizes, and protect the interests of legitimate users, before responding to the user prize drawing request, the prize drawing method further includes identity verification of the user initiating the prize drawing request.

[0120] In the application embodiments, identity verification refers to determining whether a user is a “sheep party” (such as a user who frequently participates in prize drawing or maliciously brushes prizes) through a risk control system.

[0121] The risk user group refers to a preset user set that needs to be limited in participation, which is identified by a user ID, a device number, or the like.

[0122] In an example implementation, the user can be verified by calling a preset risk control interface.

[0123] In the application embodiments, if the verification result is that the user belongs to the preset risk user group, the prize drawing request of the user is rejected.

[0124] In an example implementation, if the verification result is a risk user, the information "You cannot participate in this draw" can be returned.

[0125] If the verification result is that the user does not belong to the preset risk user group, the foregoing steps S101-S106 are executed.

[0126] The embodiments of the present application avoid the prize being maliciously occupied by intercepting the risk user, protect the rights and interests of the legal user, reduce the invalid draw request, reduce the system resource consumption, and improve the fairness of the activity.

[0127] Based on the draw method provided by the foregoing embodiments, the present application also provides a draw device. Figure 2 A structural schematic diagram of a draw device provided by the embodiments of the present application is shown in FIG. 1. Figure 2 As shown in FIG. 1, the draw device includes a draw request response module 201, a prize type determination module 202, a prize instance removal module 203, a prize instance distribution module 204, and a probability array reconstruction module 205.

[0128] The draw request response module 201 is configured to respond to a user draw request, obtain a probability array from a target cache database, and generate a random number within a total interval range delimited by a first element and a last element of the probability array.

[0129] The prize type determination module 202 is configured to determine a target prize type according to a subinterval, in which the random number falls, composed of adjacent elements of the probability array.

[0130] The prize instance removal module 203 is configured to remove a first prize instance from a prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation.

[0131] The prize instance distribution module 204 is configured to distribute the first prize instance to the user if the removal is successful.

[0132] The probability array reconstruction module 205 is configured to return first information to the user if the removal fails, and reconstruct a probability array based on the draw probability of the prize type with a current remaining number greater than zero, and update the reconstructed probability array to the target cache database.

[0133] The embodiment of the present application combines the functions of the lottery request response module 201, the prize type determination module 202, the prize instance removal module 203, the prize instance distribution module 204 and the probability array reconstruction module 205 to improve the real-time perception of the prize inventory during the lottery process to avoid the "empty" phenomenon, while enhancing the stability and response efficiency of the lottery in high-concurrency scenarios, and ensuring the accuracy of prize distribution and user experience while reducing operation and maintenance costs.

[0134] In an optional implementation, the lottery device further includes a first judgment module configured to judge whether the number of prize instances in the prize instance list corresponding to the target prize type is equal to 0 after the prize instance issuing module 204 issues the first prize instance to the user;

[0135] When the number of prize instances is equal to 0, the probability array is reconstructed based on the probability of winning the prize types whose current remaining number is greater than zero, and the reconstructed probability array is updated to the target cache database.

[0136] In an optional implementation, the target cache database further stores the total remaining number of prizes, and the lottery device further includes a second judgment module for obtaining the total remaining number of prizes before the lottery request response module 201 obtains the probability array from the target cache database;

[0137] Determine whether the total remaining number of the prizes is greater than 0;

[0138] If the total remaining number of prizes is not greater than 0, a second message is returned to the user and the current lottery process is terminated; the second message indicates that the current lottery has ended;

[0139] In the case where the total remaining number of prizes is greater than 0, the step of obtaining the probability array from the target cache database is performed.

[0140] In an optional implementation, the second judgment module is further configured to update the total remaining number of prizes stored in the target cache database after the first prize instance is distributed to the user.

[0141] In an optional implementation, the lottery device further includes a database construction module, which includes a basic data storage unit and a data preheating unit.

[0142] The basic data storage unit is used to store basic data of the target lottery activity into the target data table, wherein the basic data includes the total remaining number of prizes, the probability of winning multiple prize types, the remaining number of the multiple prize types, and the prize instances corresponding to the multiple prize types; the number of prize instances corresponding to the prize type is the remaining number of the prize type;

[0143] The data preheating unit is configured to preheat the target cache database based on the base data in the target data table.

[0144] The data preheating unit comprises:

[0145] The first storage subunit is configured to store the total remaining number of the prizes in the target cache database.

[0146] The probability array construction subunit is configured to construct a probability array based on the remaining numbers and winning probabilities of the prize types stored in the target data table, and store the probability array in the target cache database.

[0147] The second storage subunit is configured to create a corresponding prize instance list for each prize type in the target cache database, and store all prize instances corresponding to the prize type in the corresponding prize instance list.

[0148] The probability array construction subunit is specifically configured to initialize the first element of the probability array as 0.

[0149] All prize types with a remaining number greater than zero in the target data table are traversed.

[0150] For each prize type traversed, the winning probability of the prize type is added to the last element of the probability array to obtain an accumulated result.

[0151] The accumulated result is added as a new element to the end of the probability array until the traversal of all prize types with a remaining number greater than zero is completed.

[0152] In an optional implementation, the prize drawing device further comprises an identity verification module configured to verify the identity of a user initiating a prize drawing request before the prize drawing request response module 201 responds to the prize drawing request of the user.

[0153] If the verification result is that the user belongs to a preset risk user group, the prize drawing request of the user is rejected.

[0154] If the verification result is that the user does not belong to the preset risk user group, the step of responding to the prize drawing request of the user is performed.

[0155] In an optional implementation, the target cache database in the prize drawing device is a Redis database, the prize instance list is a Redis list structure, and each element in the Redis list structure is a prize instance.

[0156] In addition, the application embodiment further provides a prize drawing device, which comprises a processor and a memory.

[0157] The memory is configured to store program code and transmit the program code to the processor.

[0158] The processor is configured to execute steps of the lottery method according to instructions in the program code.

[0159] It should be noted that each embodiment in the specification is described in a progressive manner, and the same and similar parts between each embodiment can be referred to each other. Each embodiment focuses on the difference from other embodiments. Especially, the device and equipment embodiments are described relatively simply because they are basically similar to the method embodiments. The relevant parts can be referred to the part of the method embodiments. The device and equipment embodiments described above are only schematic, and the units described as separate units can or can not be physically separate, and the units described as units can or can not be physical units, that is, they can be located in one place, or distributed on multiple network units. According to the actual needs, some or all of the modules can be selected to achieve the purpose of the embodiment. Those skilled in the art can understand and implement it without creative labor.

[0160] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited to this. Any skilled person in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A lottery method, characterized in that: The method comprises: In response to a user lottery request, a probability array is retrieved from a target cache database, and a random number is generated within a total interval defined by the first and last elements of the probability array; the target cache database stores the probability array and a list of prize instances corresponding to multiple prize types; the number of prize instances in the prize instance list indicates the remaining number of prize types; the first element of the probability array is 0, and subsequent elements are the accumulated values ​​of the winning probabilities of each prize type whose remaining number is greater than zero; determining a target prize type according to a subinterval consisting of adjacent elements of the probability array into which the random number falls; Removing the first prize instance from the prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation; If the removal is successful, the first instance of the prize is issued to the user; If the removal fails, the first information is returned to the user, and the probability array is reconstructed based on the probability of winning the prize type with the current remaining number greater than zero, and the reconstructed probability array is updated to the target cache database; the first information indicates that the user did not win the prize.

2. The method according to claim 1, characterized in that After issuing the first prize instance to the user, the method further includes: Determine whether the number of prize instances in the prize instance list corresponding to the target prize type is equal to 0; When the number of prize instances is equal to 0, the probability array is reconstructed based on the probability of winning the prize types whose current remaining number is greater than zero, and the reconstructed probability array is updated to the target cache database.

3. The method according to claim 1, characterized in that The target cache database also stores the total remaining number of prizes. Before obtaining the probability array from the target cache database, the method further includes: Obtaining the total remaining quantity of the prizes; Determine whether the total remaining number of the prizes is greater than 0; If the total remaining number of prizes is not greater than 0, a second message is returned to the user and the current lottery process is terminated; the second message indicates that the current lottery has ended; In the case where the total remaining number of prizes is greater than 0, the step of obtaining the probability array from the target cache database is performed.

4. The method according to claim 3, characterized in that After issuing the first prize instance to the user, the method further includes: The total remaining number of prizes stored in the target cache database is updated.

5. The method according to claim 1, wherein The target cache database is constructed in the following manner: Storing basic data of the target lottery activity in a target data table, the basic data including the total remaining number of prizes, the probability of winning multiple prize types, the remaining number of the multiple prize types, and the prize instances corresponding to the multiple prize types; the number of prize instances corresponding to the prize type is the remaining number of the prize type; Preheating data in the target cache database based on the basic data in the target data table includes: Storing the remaining total number of prizes in the target cache database; Constructing a probability array based on the remaining quantities and winning probabilities of the various prize types stored in the target data table, and storing the probability array in the target cache database; A corresponding prize instance list is created for each prize type in the target cache database, and all prize instances corresponding to the prize type are stored in the corresponding prize instance list.

6. The method according to claim 5, characterized in that The method of constructing a probability array based on the remaining number and winning probability of the various prize types stored in the target data table includes: Initialize the first element of the probability array to 0; Traversing the target data table for all prize types whose remaining quantity is greater than zero; For each prize type traversed, the probability of winning the prize type is accumulated with the last element of the probability array to obtain an accumulated result; The accumulated result is added as a new element to the end of the probability array until all prize types with a remaining quantity greater than zero are traversed.

7. The method according to claim 1, characterized in that Before responding to the user's lottery request, the method further includes: Verify the identity of the user who initiated the lottery request; If the verification result shows that the user belongs to the preset risk user group, the user's lottery request is rejected; If the verification result shows that the user does not belong to the preset risk user group, the step of responding to the user's lottery request is executed.

8. The method according to any one of claims 1 to 7, characterized in that The target cache database is a Redis database, and the prize instance list is a Redis list structure; each element in the Redis list structure is a prize instance.

9. A lottery device, characterized in that: The device comprises: A lottery request response module is configured to, in response to a user lottery request, obtain a probability array from a target cache database and generate a random number within a total interval defined by the first and last elements of the probability array; the target cache database stores the probability array and a list of prize instances corresponding to a plurality of prize types; the number of prize instances in the prize instance list indicates the remaining number of prize types; the first element of the probability array is 0, and subsequent elements are the accumulated values ​​of the winning probabilities of each prize type whose remaining number is greater than zero; a prize type determination module, configured to determine a target prize type according to a subinterval consisting of adjacent elements of the probability array into which the random number falls; a prize instance removal module, configured to remove the first prize instance from the prize instance list corresponding to the target prize type stored in the target cache database through an atomic operation; A prize instance issuing module, configured to issue the first prize instance to the user if the removal is successful; A probability array reconstruction module is used to return a first message to the user if the removal fails, and reconstruct the probability array based on the probability of winning the prize type whose current remaining number is greater than zero, and update the reconstructed probability array to the target cache database; the first information indicates that the user did not win the prize.

10. A lottery device, characterized in that: include: Processor and memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the steps of the lottery method according to any one of claims 1 to 8 according to the instructions in the program code.