Random code generation method, apparatus, computing device and storage medium
By generating random codes through combination recursion and full permutation processing, the problems of simplicity, uniqueness, and efficient management are solved, achieving efficient generation and management of random codes and improving the resource utilization rate and information management efficiency of redemption codes.
Patent Information
- Application Number
- CN202310139349.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-20
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2043-02-20
AI Technical Summary
Existing technologies struggle to generate concise, unique, and efficiently manageable random codes, especially when the demand for redemption codes is high and utilization is low, thus failing to meet the needs of operational activities.
By recursively combining the character set and temporary variable array, a random string of a predetermined length is generated. Then, a set of random codes is generated and stored in memory through recursive processing of all permutations. The random code information is associated with the identifier, and batch generation and hash storage are supported.
Ensuring the uniqueness and simplicity of random codes improves the utilization rate of redemption code resources and facilitates management and retrieval, thereby improving information management efficiency.
Smart Images

Figure CN116166221B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer and Internet technology, and in particular to a method, apparatus, computing device and storage medium for generating random codes. Background Technology
[0002] As internet e-commerce systems have evolved, random strings composed of letter combinations or special symbols are flexibly used on various e-commerce platform activity pages to meet user verification requirements. Examples include redemption codes in e-commerce promotions, SMS verification codes sent to business system login pages, subway QR codes, shared bicycle QR codes, technical interface keys, and signature strings. Depending on the business scenario, random strings can be applied to business condition association, query verification, and other aspects.
[0003] In actual operation, redemption codes must be unique, with each code corresponding to a specific discount. Furthermore, the demand for redemption codes is often high, but the actual demand is generally only one-tenth of the expected demand. This necessitates that redemption code information be as concise as possible and easy to manage, including features such as viewing expired codes, tracking expired codes, and tracking code usage.
[0004] Currently, all business systems involved in product sales inevitably require various operational activities, the most common of which is the need for redemption codes. Whether for offline or online events, redemption codes provide excellent promotional results. For redemption codes in different usage scenarios, most require randomness and uniqueness, and a fixed number of digits, such as the distribution of Tmall car wash coupons and JD.com gift coupons, to facilitate user verification. However, some business scenarios, such as user SMS verification codes, require fewer digits and are easier to remember. Only randomness for each mobile number within a fixed time period is needed; uniqueness is less critical. Furthermore, the generated random codes need to be stored in massive quantities on the server depending on the business scenario, or stored individually for each user, for convenient access.
[0005] Furthermore, due to the specific nature of the operational activities, redemption codes need to be generated in advance to generate buzz for the event as much as possible. Additionally, redemption codes must be unique. Because the information in redemption codes must be concise, their length cannot be too long. Given the high demand and low utilization rate of redemption codes, database storage is not suitable. Therefore, a redemption code generation scheme that is concise, unique, and improves the efficiency of redemption code information management is needed to meet the aforementioned requirements.
[0006] Therefore, a random code generation method is needed to solve the problems existing in the above technical solutions. Summary of the Invention
[0007] To address this, the present invention provides a random code generation method and a random code generation apparatus to solve or at least alleviate the problems mentioned above.
[0008] According to one aspect of the present invention, a method for generating random codes is provided, executed in a computing device, comprising: acquiring a character set for generating random codes, a temporary variable array, a predetermined number of random codes, a number to be generated, and a random code identifier; performing combined recursive processing based on the character set and the temporary variable array to generate multiple random strings of predetermined length; performing full permutation recursive processing on each random string to generate multiple corresponding random codes, and storing them in a random code set, until the number of random codes generated equals the number to be generated; for each generated random code, acquiring random code information, and associating the random code information with the random code identifier and storing it in memory, wherein the random code information includes the predetermined number of random codes, the combined coordinate index and the permutation coordinate index corresponding to the random code, and the current number of random codes generated.
[0009] Optionally, in the random code generation method according to the present invention, the quantity to be generated is the quantity to be generated in a single batch, so as to generate random codes in batches and store them in a random code set corresponding to the current batch, wherein each batch corresponds to a batch number.
[0010] Optionally, the random code generation method according to the present invention further includes: transposing and scattering the random codes in the random code set to obtain a hashed random code set, and storing the hashed random code set.
[0011] Optionally, in the random code generation method according to the present invention, storing the hashed random code set includes: associating and storing each hashed random code in the hashed random code set with a corresponding batch number and business identifier in a cache.
[0012] Optionally, in the random code generation method according to the present invention, each random string is recursively processed with full permutations to generate multiple corresponding random codes, which are stored in a random code set until the number of random codes generated equals the number to be generated. This includes: for each random code generated, storing the random code in the random code set, and determining whether the number of random codes currently contained in the random code set is equal to the number to be generated; if yes, then stopping the generation of random codes; if no, then continuing to generate the next random code.
[0013] Optionally, the random code generation method according to the present invention further includes: obtaining configuration information, wherein the configuration information includes a predetermined number of bits for the random code, a batch quantity, a batch number, a quantity to be generated, and a service identifier.
[0014] Optionally, the random code generation method according to the present invention further includes: creating a random code task according to configuration information, so as to generate the plurality of random codes by executing the random code task.
[0015] Optionally, in the random code generation method according to the present invention, creating a random code task according to configuration information includes: in response to an instruction to generate a random code, obtaining configuration information from the instruction, and creating a random code task according to the configuration information.
[0016] Optionally, in the random code generation method according to the present invention, the random code is a redemption code.
[0017] According to one aspect of the present invention, a random code generation apparatus is provided, residing in a computing device, comprising: an acquisition module adapted to acquire a character set for generating random codes, a temporary variable array, a predetermined number of random codes, a number to be generated, and a random code identifier; a first processing module adapted to perform combined recursive processing based on the character set and the temporary variable array to generate multiple random strings of predetermined length; a second processing module adapted to perform full permutation recursive processing on each random string to generate multiple corresponding random codes, and store them in a random code set until the number of random codes generated equals the number to be generated; and a storage module adapted to acquire random code information for each generated random code, and associate the random code information with the random code identifier and store it in memory, wherein the random code information includes the predetermined number of random codes, the combined coordinate index and the permutation coordinate index corresponding to the random code, and the current number of random codes generated.
[0018] According to one aspect of the present invention, a computing device is provided, comprising: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by the at least one processor, the program instructions including instructions for performing the random code generation method as described above.
[0019] According to one aspect of the present invention, a readable storage medium storing program instructions is provided, which, when read and executed by a computing device, causes the computing device to perform the random code generation method described above.
[0020] According to the technical solution of the present invention, a method for generating random codes is provided. This method involves performing a combined recursive process based on a character set and a temporary variable array used to generate random codes, to generate multiple random strings of predetermined length. Then, each random string is subjected to a full permutation recursive process to generate multiple corresponding random codes, which are stored in a random code set until the number of generated random codes equals the number to be generated. Furthermore, for each generated random code, random code information (including the predetermined length of the random code, the combined coordinate index, the permutation coordinate index, and the current number of generated random codes) is obtained, and the random code information is associated with a random code identifier and stored in memory. In this way, the present invention can cyclically generate a specified number of random codes while ensuring the uniqueness and simplicity of the random codes, improving the utilization rate of redemption code resources in redemption scenarios. Moreover, by associating the random code information with the random code identifier, it is convenient to query the usage status of random codes, improving the information management efficiency of random codes.
[0021] Furthermore, this invention can generate random codes in batches, and by transposing and shuffling the random codes in the set, each hashed random code is associated with and stored in the cache based on its corresponding batch number and business identifier. This facilitates the differentiation of the use of random codes in different business scenarios.
[0022] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention and to implement it in accordance with the contents of the specification, and in order to make the above and other objects, features and advantages of the present invention more apparent and understandable, specific embodiments of the present invention are described below. Attached Figure Description
[0023] To achieve the foregoing and related objectives, certain illustrative aspects are described herein in conjunction with the following description and accompanying drawings. These aspects indicate various ways in which the principles disclosed herein may be practiced, and all aspects and their equivalents are intended to fall within the scope of the claimed subject matter. The foregoing and other objectives, features, and advantages of this disclosure will become more apparent from the following detailed description, taken in conjunction with the accompanying drawings. Throughout this disclosure, the same reference numerals generally refer to the same parts or elements.
[0024] Figure 1 A schematic diagram of a computing device 100 according to an embodiment of the present invention is shown;
[0025] Figure 2 A flowchart illustrating a random code generation method 200 according to an embodiment of the present invention is shown;
[0026] Figure 3 A schematic diagram of a random code generation apparatus 300 according to an embodiment of the present invention is shown. Detailed Implementation
[0027] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
[0028] Figure 1 A schematic diagram of a computing device 100 according to an embodiment of the present invention is shown. Figure 1 As shown, in a basic configuration, computing device 100 includes at least one processing unit 102 and system memory 104. According to one aspect, depending on the configuration and type of the computing device, the processing unit 102 may be implemented as a processor. System memory 104 includes, but is not limited to, volatile memory (e.g., random access memory), non-volatile memory (e.g., read-only memory), flash memory, or any combination of such memory. According to one aspect, system memory 104 includes an operating system 105.
[0029] According to one aspect, operating system 105 is, for example, suitable for controlling the operation of computing device 100. Furthermore, examples are practiced in conjunction with graphics libraries, other operating systems, or any other applications, and are not limited to any particular application or system. Figure 1 The basic configuration is illustrated by the components within the dashed lines. According to one aspect, the computing device 100 has additional features or functions. For example, according to one aspect, the computing device 100 includes additional data storage devices (removable and / or non-removable), such as disks, optical discs, or magnetic tapes. This additional storage... Figure 1 The middle part is shown by removable storage device 109 and non-removable storage device 110.
[0030] As stated above, according to one aspect, program module 103 is stored in system memory 104. According to one aspect, program module 103 may include one or more applications. The present invention does not limit the type of application; for example, applications may include: email and contact applications, word processing applications, spreadsheet applications, database applications, slideshow applications, drawing or computer-aided applications, web browser applications, etc.
[0031] According to one aspect, program module 103 may include a random code generation device 300, which includes a plurality of program instructions adapted to perform the random code generation method 200 of the present invention.
[0032] According to one aspect, examples can be practiced on circuits including discrete electronic components, packaged or integrated electronic chips containing logic gates, circuits utilizing microprocessors, or on a single chip containing electronic components or a microprocessor. For example, it can be practiced via wherein... Figure 1 Each or many of the components shown can be implemented as an example by integrating a System-on-a-Chip (SOC) on a single integrated circuit. According to one aspect, such an SOC device may include one or more processing units, graphics units, communication units, system virtualization units, and various application functions, all integrated (or “burned in”) as a single integrated circuit onto a chip substrate. When operating via the SOC, the functions described herein can be operated via dedicated logic integrated on a single integrated circuit (chip) with other components of the computing device 100. Embodiments of the invention can also be implemented using other techniques capable of performing logical operations (e.g., AND, OR, and NOT), including but not limited to mechanical, optical, fluid, and quantum technologies. Additionally, embodiments of the invention can be implemented within a general-purpose computer or in any other circuit or system.
[0033] According to one aspect, computing device 100 may also have one or more input devices 112, such as a keyboard, mouse, pen, voice input device, touch input device, etc. It may also include output devices 114, such as a display, speaker, printer, etc. The foregoing devices are examples and other devices may also be used. Computing device 100 may include one or more communication connections 116 that allow communication with other computing devices 118. Examples of suitable communication connections 116 include, but are not limited to: RF transmitter, receiver and / or transceiver circuitry; Universal Serial Bus (USB), parallel and / or serial ports.
[0034] As used herein, the term computer-readable medium includes computer storage medium. Computer storage medium can include volatile and non-volatile, removable and non-removable media implemented using any method or technology for storing information (e.g., computer-readable instructions, data structures, or program module 103). System memory 104, removable storage device 109, and non-removable storage device 110 are examples of computer storage media (i.e., memory storage). Computer storage media can include random access memory (RAM), read-only memory (ROM), electrically erasable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape, magnetic tape, disk storage or other magnetic storage devices, or any other article of manufacture that can be used to store information and is accessible by computing device 100. According to one aspect, any such computer storage medium can be part of computing device 100. Computer storage media does not include carrier waves or other transmitted data signals.
[0035] According to one aspect, the communication medium is implemented by computer-readable instructions, data structures, program modules 103, or other data in a modulated data signal (e.g., a carrier wave or other transmission mechanism), and includes any information transmission medium. According to one aspect, the term "modulated data signal" describes a signal having one or more sets of characteristics or altered in a manner that encodes information in the signal. By way of example and not limitation, the communication medium includes wired media such as wired networks or direct wired connections, and wireless media such as acoustic, radio frequency (RF), infrared, and other wireless media.
[0036] In an embodiment of the present invention, a computing device 100 is configured to execute a random code generation method 200 according to the present invention. The computing device 100 includes one or more processors and one or more readable storage media storing program instructions, which, when configured to be executed by the one or more processors, cause the computing device to execute the random code generation method 200 of the present invention. By executing the random code generation method 200 of the present invention, an ID with a service identifier that is outside the current time range can be generated.
[0037] According to one embodiment of the present invention, a random code generation device 300 is deployed in a computing device 100, and the random code generation device 300 is configured to execute a random code generation method 200 according to the present invention. The random code generation device 300 includes a plurality of program instructions for executing the random code generation method 200 of the present invention, which can instruct a processor to execute the random code generation method 200 according to the present invention.
[0038] Figure 2A flowchart illustrating a random code generation method 200 according to an embodiment of the present invention is shown. The random code generation method 200 is adapted to be executed in a computing device 100, specifically in a random code generation apparatus 300 of the computing device 100.
[0039] It should be noted that the random code generated by the method 200 according to the present invention can be, for example, a redemption code, but the present invention does not limit the specific application scenarios of the random code.
[0040] like Figure 2 As shown, method 200 begins with step 210.
[0041] First, in step 210, the character set used to generate random codes, the temporary variable array b, the predetermined number of bits N for the random codes, the number to be generated, and the random code identifier (key) are obtained.
[0042] Here, the character set used to generate the random code can include multiple characters, such as abcdefghgklmnipqrstuvwxyz023456789.
[0043] It should be noted that the random code identifier key can be determined based on the predetermined number of bits N of the random code. For example, if a 5-digit random code is to be generated (the predetermined number of bits N = 5), the random code identifier can be RandCode_5_Create. The object corresponding to the random code identifier key can be, for example, {str_:"random number", arr_i:"combined index", arr_y:"permutation index", count_:"number generated"}.
[0044] Subsequently, in step 220, a combined recursive process is performed based on the character set and the temporary variable array to generate multiple random strings of a predetermined length. That is, each generated random string includes a predetermined length (N) of characters. Specifically, a pre-created combined recursive algorithm can be used to perform combined recursive processing based on the character set and the temporary variable array.
[0045] For example, we can obtain the string A = abcdefghjkmnopqrstuvwxyz023456789 from the character set mentioned above, and use it as a random value for the string. We set m = the length len of string A. Assuming the predetermined number of digits N for the random code is 5, we set the loop coordinate i = m and perform a reverse loop, with the minimum lower limit of i being the predetermined number of digits N for the random code. We set the maximum length of the temporary variable array b to n, and b[m-1] = i-1. This expression means: in this loop, we fill the array with 5 random strings until the array is completely filled; otherwise, we continue the recursive loop until the value of m-1 is less than 1 in each call, at which point the current combination recursive process ends. We take the coordinates in the temporary variable array b and map them to a character in the corresponding random string A. For example, the random string mapped to the current temporary variable array b could be abcde, and we can record the loop coordinate i value for the current combination.
[0046] Next, in step 230, a pre-created recursive algorithm for all permutations can be invoked to recursively process each of the generated random strings to generate multiple corresponding random codes, which are then stored in a random code set until the number of generated random codes equals the number to be generated. When the number of generated random codes equals the number to be generated, the recursive generation of random codes can be terminated.
[0047] Specifically, for each recursive loop that generates a random code, the random code is stored in a random code set, and it is determined whether the number of random codes currently contained in the random code set (i.e., the number of random codes currently generated) is equal to the number to be generated. If they are equal, the recursive loop stops generating random codes. Otherwise, if the number of random codes currently generated is less than the number to be generated, the recursive loop continues to generate the next random code.
[0048] For example, you can set the count of random codes (i.e., the number of random codes that have been generated) to count. When count equals the number of random codes to be generated, the recursive loop for generating random codes ends.
[0049] In one implementation, a random code set Arr can be pre-set, with a sorting start index (startindex) and an end index (endindex) equal to the predetermined number of bits N for the random code. The random string requiring recursive permutation processing is given a loop, and a string array b can be obtained. Within the loop, t[startindex] and t[i] are swapped, and startindex is set to startindex + 1. Next, the current recursive permutation algorithm is called to rearrange the random string (e.g., abcde) into a new random string (which can be called a "random code," e.g., acbde). The algorithm is called repeatedly, swapping t[startindex] and t[i] again, until the recursive processing of the random string abcde is complete, yielding multiple random codes. During the recursive generation of random codes, it can be checked whether the number of generated random codes (count) equals the number to be generated. If they are equal, the current recursive permutation processing flow can be terminated. Furthermore, for each generated random code, the combination coordinate index, permutation coordinate index, and the number of generated random codes can be set to continue generation next time.
[0050] Furthermore, in step 240, for each random code generated in step 230, random code information is obtained, and the random code information is associated with a random code identifier (key) and stored in memory. That is, the random code information is stored as an object in the memory set associated with the random code identifier (key).
[0051] Specifically, the random code information includes the predetermined number of bits in the random code, the combined coordinate index and the permutation coordinate index corresponding to the random code, and the number of random codes that have been generated so far.
[0052] According to one embodiment of the present invention, the quantity to be generated can specifically be the quantity to be generated in a single batch, so as to generate random codes in batches, and each batch can correspond to a random code set. Thus, each random code generated in the current batch can be stored in the random code set corresponding to the current batch. In addition, each batch corresponds to a batch number (uniquely corresponding to the batch).
[0053] It should be noted that when the number of random codes to be generated is large, the number of cyclic batches can be calculated: intpage = (rand_num + pageSize - 1) / pageSize, so that random codes can be generated in batches. Therefore, when generating random codes in batches, the number of codes to be generated in the current batch needs to be set to the number of codes to be generated per batch.
[0054] In one embodiment, after generating the random code set for each batch, since the random codes in the random code set are arranged in an ordered manner, a round-robin shuffling algorithm can be used to shuffle the random codes in the random code set by transposing them, thereby obtaining a hashed random code set, which can then be stored. Specifically, any random code in the random code set can be randomly selected in a loop and transposed with the last random code, and intermediate variables can be used to randomly transpose and assign values to each random code in the random code set.
[0055] In one embodiment, each hashed random code in the hashed random code set can be associated and stored in a cache based on its corresponding batch number and business identifier. For example, it can be associated and stored in a hashtable cached in Redis. Simultaneously, each hashed random code in the hashed random code set can be exported to an Excel document, packaged and compressed into a compressed file, and then stored on a file server.
[0056] By associating and storing each hashed random code in the hashed random code set with its corresponding batch number and business identifier in the cache, it is easier to query the usage of the random codes and improve the efficiency of random code information management.
[0057] In another embodiment of the present invention, before executing step 210, configuration information can be obtained (from the operation backend). This configuration information may specifically include the predetermined number of digits (N) of the random code, the batch quantity, the batch number, the quantity to be generated, the business identifier, and the number of random codes exported. Furthermore, for redemption codes, the configuration information may also include the redemption start time and the redemption end time. Thus, in step 210, the predetermined number of digits N, the quantity to be generated, and the random code identifier can be obtained from the configuration information.
[0058] In one implementation, after obtaining the configuration information, a random code task can be created based on the configuration information. This allows multiple random codes to be generated by executing the random code task. Optionally, the computing device 100 can receive a random code generation instruction sent by the operations backend. Subsequently, in response to the random code generation instruction, configuration information can be obtained from the instruction, and then a random code task can be created based on the configuration information.
[0059] In one embodiment, the random code can be a redemption code. Each redemption code corresponds to a specific discount method and contains a unique corresponding number.
[0060] It should be noted that after generating multiple redemption codes according to method 200 of the present invention, the redemption codes can be distributed to the user's mobile terminal via SMS or application push. After obtaining the redemption code, the user can enter the redemption code in the redemption module to send the redemption code to the computing device for verification. Subsequently, the computing device can perform verification based on the redemption code information. The specific verification process includes: checking whether the current redemption code exists in the cache, verifying the timeliness of the redemption code, verifying the business identifier of the redemption code, verifying whether the redemption code has been used, and verifying the number of times the redemption code has been entered incorrectly.
[0061] Figure 3 A schematic diagram of a random code generation apparatus 300 according to an embodiment of the present invention is shown. The random code generation apparatus 300 resides in a computing device 100. The random code generation apparatus 300 can be configured to perform the random code generation method 200 of the present invention.
[0062] like Figure 3 As shown, the random code generation device 300 includes an acquisition module 310, a first processing module 320, a second processing module 330, and a storage module 340 that are connected in sequence.
[0063] The acquisition module 310 can acquire the character set, temporary variable array, predetermined number of random code bits N, number of random codes to be generated, and random code identifier for generating random codes. The first processing module 320 can perform combined recursive processing based on the character set and temporary variable array to generate multiple random strings of predetermined length. The second processing module 330 can perform full permutation recursive processing on each random string to generate multiple corresponding random codes and store them in a random code set until the number of generated random codes equals the number of codes to be generated. For each generated random code, the storage module 340 can acquire the random code information and associate the random code information with the random code identifier in memory. The random code information includes the predetermined number of random code bits, the combined coordinate index and permutation coordinate index corresponding to the random code, and the current number of random codes generated.
[0064] It should be noted that the acquisition module 310 is used to execute the aforementioned step 210, the first processing module 320 is used to execute the aforementioned step 220, the second processing module 330 is used to execute the aforementioned step 230, and the storage module 340 is used to execute the aforementioned step 240. The specific execution logic of the acquisition module 310, the first processing module 320, the second processing module 330, and the storage module 340 can be found in the description of steps 210 to 240 in method 200 above, and will not be repeated here.
[0065] According to the random code generation method 200 of the present invention, based on a character set and a temporary variable array used for generating random codes, a combined recursive process is performed to generate multiple random strings of predetermined length. Then, a full permutation recursive process is performed on each random string to generate corresponding multiple random codes, which are stored in a random code set until the number of generated random codes equals the number to be generated. Furthermore, for each generated random code, random code information (including the predetermined length of the random code, the combined coordinate index, the permutation coordinate index, and the current number of generated random codes) is obtained, and the random code information is associated with a random code identifier and stored in memory. In this way, the present invention can cyclically generate a specified number of random codes while ensuring the uniqueness and simplicity of the random codes, improving the utilization rate of redemption code resources in redemption scenarios. Moreover, by associating the random code information with the random code identifier, it is convenient to query the usage status of random codes, improving the information management efficiency of random codes.
[0066] Furthermore, this invention can generate random codes in batches, and by transposing and shuffling the random codes in the set, each hashed random code is associated with and stored in the cache based on its corresponding batch number and business identifier. This facilitates the differentiation of the use of random codes in different business scenarios.
[0067] A8. The method as described in A7, wherein creating a random code task based on configuration information includes: in response to an instruction to generate a random code, obtaining configuration information from the instruction, and creating a random code task based on the configuration information.
[0068] A9. The method as described in any one of A1-A8, wherein the random code is a redemption code.
[0069] The various techniques described herein can be implemented in combination with hardware or software, or a combination thereof. Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, can take the form of program code (i.e., instructions) embedded in a tangible medium, such as a removable hard disk, USB flash drive, floppy disk, CD-ROM, or any other machine-readable storage medium, wherein when the program is loaded into and executed by a machine such as a computer, the machine becomes an apparatus for practicing the present invention.
[0070] When the program code is executed on a programmable computer, the mobile terminal generally includes a processor, a processor-readable storage medium (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device. The memory is configured to store program code; the processor is configured to execute the random code generation method of the present invention according to instructions in the program code stored in the memory.
[0071] By way of example, and not limitation, readable media include readable storage media and communication media. Readable storage media stores information such as computer-readable instructions, data structures, program modules, or other data. Communication media generally embodies computer-readable instructions, data structures, program modules, or other data in the form of modulated data signals such as carrier waves or other transmission mechanisms, and includes any information delivery medium. Any combination of the above is also included within the scope of readable media.
[0072] In the specification provided herein, the algorithms and displays are not inherently related to any particular computer, virtual system, or other device. Various general-purpose systems can also be used with the examples of this invention. The required structure for constructing such systems is apparent from the above description. Furthermore, this invention is not directed to any particular programming language. It should be understood that the contents of the invention described herein can be implemented using various programming languages, and the above description of specific languages is for the purpose of disclosing the best mode of implementation of the invention.
[0073] Numerous specific details are set forth in the specification provided herein. However, it will be understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.
[0074] Similarly, it should be understood that, in order to streamline this disclosure and aid in understanding one or more of the various aspects of the invention, in the above description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof.
[0075] Those skilled in the art will understand that modules, units, or components of the devices disclosed in the examples herein can be arranged in the devices described in this embodiment, or alternatively, can be located in one or more devices different from the devices in this example. The modules in the foregoing examples can be combined into a single module or, in addition, can be divided into multiple sub-modules.
[0076] Those skilled in the art will understand that the modules in the device of the embodiment can be adaptively changed and placed in one or more devices different from that embodiment. Modules, units, or components in the embodiment can be combined into a single module, unit, or component, and further, they can be divided into multiple sub-modules, sub-units, or sub-components.
[0077] Furthermore, those skilled in the art will understand that although some embodiments described herein include certain features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention and form different embodiments.
[0078] Furthermore, some of the embodiments described herein are methods or combinations of method elements that can be implemented by a processor of a computer system or by other means of performing the functions. Therefore, a processor having the necessary instructions for implementing the methods or method elements forms means for implementing the methods or method elements. Furthermore, the elements described herein in the apparatus embodiments are examples of means for implementing the functions performed by the objective elements for carrying out the invention.
[0079] As used herein, unless otherwise specified, the use of ordinal numbers such as “first,” “second,” “third,” etc., to describe ordinary objects merely indicates different instances of similar objects and is not intended to imply that the objects being described must have a given order in time, space, ordering, or any other manner.
[0080] Although the invention has been described with respect to a limited number of embodiments, those skilled in the art will understand from the foregoing description that other embodiments are conceivable within the scope of the invention described herein. Furthermore, it should be noted that the language used in this specification has been chosen primarily for readability and edibility purposes, and not for the purpose of explaining or limiting the subject matter of the invention.
Claims
1. A method for generating random codes, executed in a computing device, comprising: obtaining a character set for generating random codes, a temporary variable array, a predetermined length of random codes, a quantity to be generated, and a random code identifier; performing combination recursive processing based on the character set and the temporary variable array to generate a plurality of random strings of the predetermined length; performing full permutation recursive processing on each random string to generate a corresponding plurality of random codes and store them in a random code set until the quantity of generated random codes equals the quantity to be generated; permuting and scattering the random codes in the random code set to obtain a hashed random code set and store the hashed random code set; storing each hashed random code in the hashed random code set in a cache based on a corresponding batch number and a service identifier; and for each generated random code, obtaining random code information and storing the random code information in association with the random code identifier in a memory, wherein the random code information includes the predetermined length of random codes, combination coordinate indexes and permutation coordinate indexes corresponding to the random code, and the quantity of generated random codes. 2.The method of claim 1, wherein: the quantity to be generated is a single-batch quantity to be generated, so that the random codes are generated in batches and stored in a random code set corresponding to a current batch, wherein each batch corresponds to a batch number.
3. The method of claim 1 or 2, wherein, performing full permutation recursive processing on each random string to generate a corresponding plurality of random codes and store them in a random code set until the quantity of generated random codes equals the quantity to be generated, comprises: storing the random code in the random code set each time a random code is generated, and determining whether the quantity of random codes currently contained in the random code set equals the quantity to be generated; if yes, stopping generating random codes; if no, continuing to generate the next random code. 4.The method of claim 1 or 2, further comprising: obtaining configuration information including the predetermined length of random codes, the batch quantity, the batch number, the quantity to be generated, and the service identifier. 5.The method of claim 4, further comprising: creating a random code task according to the configuration information, so that the plurality of random codes are generated by executing the random code task.
6. The method of claim 5, wherein, creating a random code task according to the configuration information, comprises: in response to an instruction to generate random codes, obtaining configuration information from the instruction and creating a random code task according to the configuration information. 7.The method of claim 1 or 2, wherein the random codes are exchange codes. 8.A random code generation apparatus residing in a computing device and adapted to execute the method of any one of claims 1-7, the apparatus comprising: an obtaining module adapted to obtain a character set for generating random codes, a temporary variable array, a predetermined length of random codes, a quantity to be generated, and a random code identifier; a first processing module adapted to perform combination recursive processing based on the character set and the temporary variable array to generate a plurality of random strings of the predetermined length; and a second processing module adapted to perform full permutation recursive processing on each random string to generate a corresponding plurality of random codes and store them in a random code set until the quantity of generated random codes equals the quantity to be generated. a second processing module adapted to perform full permutation recursive processing on each random string to generate a plurality of random codes corresponding thereto and store in a random code set until the number of random codes generated is equal to the number to be generated; a storage module adapted to, for each random code generated, obtain random code information and store the random code information in association with the random code identification in the memory, wherein the random code information includes a predetermined number of digits of the random code, combination coordinate index and permutation coordinate index corresponding to the random code, and the number of random codes generated so far.
9. A computing device comprising: at least one processor; and a memory storing program instructions configured to be executed by the at least one processor, the program instructions comprising instructions for performing the method of any one of claims 1-7.
10. A readable storage medium storing program instructions, which when read and executed by a computing device, cause the computing device to perform the method of any one of claims 1-7.
Citation Information
Patent Citations
Voucher code processing method and device and storage medium
CN111723360A
Method for enhancing password security and terminal
CN112632524A