Method and apparatus for matching non-overlapping templates for random number detection, electronic device
By initializing and judging the array of non-overlapping templates, the number of non-overlapping times of multiple target templates can be determined by reading the non-overlapping template only once, which solves the problem of high hardware performance requirements in the prior art and realizes fast random number testing.
Patent Information
- Application Number
- CN202311324157.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-12
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-10-12
AI Technical Summary
Existing optimization schemes for non-overlapping template matching tests have high hardware performance requirements, which is particularly unfriendly to devices with poor performance or no GPU hardware, resulting in slow test speeds.
By initializing the target template array and the statistics array, the array element values are determined using the target template, the non-overlapping templates are shifted to obtain the subsequences, and the subsequences are determined to be the target templates by using the target template array. The statistics array is then updated. Only one reading of the non-overlapping template is needed to determine the number of non-overlapping times of multiple target templates.
It significantly reduces hardware requirements, shortens the overall testing time for random tests, and improves testing speed, enabling fast testing even on machines with poor performance.
Smart Images

Figure CN117493093B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of random number testing, and more specifically, to a method and apparatus for matching non-overlapping templates for random number detection, an electronic device, and a non-transient computer-readable storage medium. Background Technology
[0002] Random numbers are widely used in cryptography, spread spectrum communication, Monte Carlo methods, and other technological fields, leading to extensive applications of randomness testing. Taking a cryptographic application in everyday life—security chips—as an example, security chips utilize external physical noise sources, such as minute vibrations and ambient temperature, to generate unpredictable random numbers through methods like direct amplification and oscillatory sampling. These random numbers serve as the foundation for digital signatures and key generation, and the quality of the generated random numbers directly affects the upper and lower limits of the chip's security. Therefore, during the design of security chips, developers need to conduct extensive testing on the random numbers generated by the chip.
[0003] The core of random number testing is to measure and evaluate multiple statistical characteristics of random numbers through carefully tested methods. The NIST-Special Publication 800-22 testing standard (hereinafter referred to as the "NIST standard") is based on rigorous theoretical analysis, and its professionalism and authority are widely recognized by the international information security community. However, in existing technologies, the accompanying testing tools released with this standard are not satisfactory in terms of testing speed. In recent years, many researchers have attempted to optimize the implementation of testing methods, but most have focused on how to fully utilize newer hardware devices such as GPUs to achieve parallel testing of multiple files. The NIST standard includes 16 test items, among which the non-overlapping template matching test is the most time-consuming, accounting for about 40%.
[0004] Existing optimization schemes for non-overlapping template matching tests mostly focus on how to make full use of more powerful hardware tools such as GPUs, but this approach is not friendly to devices with poor performance or without GPU hardware. Summary of the Invention
[0005] This application aims to propose a matching method and apparatus, electronic device, and non-transient computer-readable storage medium for non-overlapping templates in random number detection, in order to solve the problem that existing optimization schemes for non-overlapping template matching tests have high hardware performance requirements.
[0006] According to one aspect of this application, a matching method for non-overlapping templates for random number detection is proposed, comprising: initializing a target template array and a statistical array according to the length of the target template; determining the element value at the corresponding position in the target template array using the target template; shifting the non-overlapping template to obtain a subsequence of the non-overlapping template; determining whether the subsequence is the target template using the target template array; and updating the statistical array according to the determination result.
[0007] According to some embodiments, initializing a target template array and a statistics array based on the length of the target template includes: determining the lengths of the target template array and the statistics array based on the length of the target template.
[0008] According to some embodiments, the target template array and the statistical array have equal lengths and both satisfy the following formula:
[0009] n=2 m +1, where m is the length of the target template and n is the length of the statistical array and the target template array.
[0010] According to some embodiments, determining the element value at the corresponding position of the target template array using the target template includes: calculating the decimal value of the target template; determining the element position of the target template array using the decimal value; and setting the value corresponding to the determined element position of the target template array as a preset value of the target template array.
[0011] According to some embodiments, before determining whether the subsequence is the target template using the target template array, the matching method further includes: initializing a boundary array according to the length of the target template.
[0012] According to some embodiments, determining whether a subsequence is the target template using the target template array includes: recording the position of the last element of the subsequence in the non-overlapping template; calculating the decimal value of the subsequence; using the decimal value to determine the element positions of the target template array and the element positions of the boundary array; determining whether the value corresponding to the element position of the target template array is a preset value of the target template array, and whether the value corresponding to the element position of the boundary array is not greater than the position of the last element of the subsequence in the non-overlapping template; if the value corresponding to the element position of the target template array is a preset value of the target template array, and the value corresponding to the element position of the boundary array is not greater than the position of the last element of the subsequence in the non-overlapping template, then the subsequence is determined to be the target template.
[0013] According to some embodiments, determining whether the subsequence is the target template using the target template array further includes: if the subsequence is the target template, updating the boundary array using the decimal value of the subsequence, the length of the target template, and the position of the last element of the subsequence in the non-overlapping template.
[0014] According to some embodiments, the boundary array is updated by the following formula:
[0015] boundary[var] = point + m
[0016] Wherein, boundary is the boundary array, var is the decimal value of the subsequence, point is the position of the last element of the subsequence in the non-overlapping template, and m is the length of the target template.
[0017] According to some embodiments, after updating the statistical array based on the judgment result, the matching method further includes repeatedly performing the following steps until the last position of the non-overlapping template is reached: shifting the non-overlapping template to obtain a subsequence of the non-overlapping template; using the target template array to determine whether the subsequence is the target template; and updating the statistical array based on the judgment result.
[0018] According to one aspect of this application, a matching device for non-overlapping templates is proposed, comprising: an array initialization unit for initializing a target template array and a statistical array according to the length of a target template; a target template element value determination unit for determining the element value at a corresponding position in the target template array using the target template; a non-overlapping template shifting unit for shifting the non-overlapping template to obtain a subsequence of the target template array; a subsequence judgment unit for judging whether the subsequence is the target template using the target template array; and a statistical array updating unit for updating the statistical array according to the judgment result.
[0019] According to one aspect of this application, an electronic device is provided, comprising: a processor; and a memory storing a computer program that, when executed by the processor, causes the processor to perform a matching method as described in any of the preceding embodiments.
[0020] According to one aspect of this application, a non-transitory computer-readable storage medium is provided, on which computer-readable instructions are stored, which, when executed by a processor, cause the processor to perform the matching method as described in any of the preceding embodiments.
[0021] According to some embodiments, the non-overlapping count of multiple target templates within a non-overlapping template can be determined by reading the non-overlapping template only once. Compared to existing technologies, this significantly reduces hardware requirements and decreases the overall testing time for random testing.
[0022] It should be understood that the above general description and the following detailed description are merely exemplary and do not limit this application. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. The above and other objectives, features, and advantages of this application will become more apparent by referring to the accompanying drawings and describing exemplary embodiments in detail.
[0024] Figure 1 A flowchart of a matching method for non-overlapping templates for random number detection, implemented according to an example of this application, is shown.
[0025] Figure 2 A flowchart illustrating a method for determining the element value at a corresponding position in the target template array according to an example embodiment of this application is shown.
[0026] Figure 3 A flowchart illustrating a method for determining whether a subsequence of a non-overlapping template is the target template according to an example embodiment of this application is shown.
[0027] Figure 4 A flowchart of another matching method for non-overlapping templates for random number detection according to an example embodiment of this application is shown.
[0028] Figure 5 A block diagram of a matching device for a non-overlapping template according to an example embodiment of this application is shown.
[0029] Figure 6 An electronic device is shown according to an exemplary embodiment of this application. Detailed Implementation
[0030] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, they are provided so that this application will be thorough and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The same drawings in the figures show the same or similar parts, and therefore repeated descriptions of them will be omitted.
[0031] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0032] The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a full understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced without one or more of these specific details, or other methods, components, materials, apparatus, or operations may be employed. In these cases, well-known structures, methods, apparatuses, implementations, materials, or operations will not be shown or described in detail.
[0033] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0034] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0035] The specific embodiments according to this application will now be described in detail with reference to the accompanying drawings.
[0036] Figure 1 The following is a flowchart illustrating a matching method for non-overlapping templates for random number detection implemented according to an example of this application. Figure 1 Taking an example, a matching method for non-overlapping templates for random number detection implemented according to an example of this application will be described in detail.
[0037] like Figure 1 As shown, in step S101, the target template array and the statistics array are initialized according to the length of the target template.
[0038] According to an embodiment of this application, the target template array is used to store the decimal number corresponding to the target template.
[0039] In this embodiment, step S101 includes:
[0040] Step S1011: Determine the lengths of the target template array and the statistics array based on the length of the target template;
[0041] Step S1013: Set the element values of the target template array and the statistics array to the first preset value, for example, 0.
[0042] In some embodiments, assuming the length of the target template is m, the lengths of the target template array and the statistical array are determined to satisfy the following formula (1).
[0043] n=2 m +1 (1)
[0044] In step S103, the element value at the corresponding position in the target template array is determined using the target template.
[0045] In this embodiment, the decimal number corresponding to the target template is recorded in the target template array.
[0046] In step S105, the non-overlapping template is shifted to obtain a subsequence of the non-overlapping template.
[0047] It should be noted here that... Figure 1 The illustrated embodiment searches for the number of times the target template appears in the non-overlapping templates. Therefore, it can be understood that the length of the subsequence of the non-overlapping templates obtained in step S105 is the same as the length of the target template.
[0048] For example, assuming the non-overlapping template is 00110101000101011101 and the target template is 1101, then when executing this embodiment, the first subsequence of the non-overlapping template is 0011.
[0049] In step S107, the target template array is used to determine whether the subsequence is the target template.
[0050] The core of non-overlapping template matching is to find the number of times each target sequence appears in the non-overlapping template, and the positions of the occurrences cannot overlap.
[0051] For example, for a non-overlapping template 101010, when the target template is 1010, the target template appears only once in the non-overlapping template, instead of twice.
[0052] In step S109, the statistical array is updated based on the judgment result.
[0053] According to an embodiment of this application, a statistical array is used to store the number of times the target template appears in the non-overlapping template.
[0054] For example, assuming the non-overlapping template is 00110101000101011101, the target template is 1101, the length of the target template is 4, and the corresponding decimal value is 13, then the length of the statistical array value is determined to be 17 according to formula (1), and the number of times the target template appears in the non-overlapping template is 2, then value
[13] = 2.
[0055] Understandably, non-overlapping template matching involves finding the number of times each target sequence appears in a non-overlapping template, provided that the positions of these occurrences do not overlap. Therefore, Figure 1 The method shown involves shifting one position at a time and then comparing the resulting non-overlapping template subsequence with the target template to determine if the subsequence is identical to the target template. After the determination, if the non-overlapping template has not yet been completely shifted, steps S105 to S107 need to be executed repeatedly until all non-overlapping templates have been traversed.
[0056] according to Figure 1 The illustrated embodiment only requires reading the non-overlapping template once to determine the non-overlapping count of multiple target templates within the non-overlapping template. Compared to existing technologies, this significantly reduces hardware requirements and decreases the overall testing time for random testing.
[0057] Figure 2 A flowchart illustrating a method for determining the element value at a corresponding position in the target template array according to an example embodiment of this application is shown, as follows: Figure 2 As shown, step S103 may include sub-steps S1031, S1033, and S1035, wherein,
[0058] In sub-step S1031, the decimal value of the target template is calculated;
[0059] In sub-step S1033, the element positions of the target template array are determined using the decimal values;
[0060] In sub-step S1035, the value corresponding to the determined element position of the target template array is set to the preset value of the target template array.
[0061] For example, assuming the non-overlapping template is 00110101000101011101 and the binary value of the target template is 1101, the corresponding decimal number is 13, then the element at position 13 of the target array target is set to the second preset value, for example, target
[13] is set to 1.
[0062] According to an embodiment of this application, before step S106, Figure 1 The matching method shown further includes initializing a boundary array based on the length of the target template. The initialized boundary array is used to record whether the subsequence is the target template when the non-overlapping template is shifted, using the boundary positions.
[0063] Figure 3 A flowchart illustrating a method for determining whether a subsequence of a non-overlapping template is the target template, according to an example embodiment of this application, is shown. Figure 3 As shown, step S107 may include sub-steps S1071, S1073, S1075, S1077, and S1079, wherein,
[0064] In sub-step S1071, the position of the last element of the sub-sequence in the non-overlapping template is recorded;
[0065] In sub-step S1073, the decimal value of the sub-sequence is calculated;
[0066] In sub-step S1075, the element positions of the target template array and the element positions of the boundary array are determined using the decimal values.
[0067] In sub-step S1077, it is determined whether the value corresponding to the element position of the target template array is a preset value of the target template array, and whether the value corresponding to the element position of the boundary array is not greater than the position of the last element of the sub-sequence in the non-overlapping template;
[0068] In sub-step S1079, if the value corresponding to the element position of the target template array is a preset value of the target template array, and the value corresponding to the element position of the boundary array is not greater than the position of the last element of the sub-sequence in the non-overlapping template, then the sub-sequence is determined to be the target template.
[0069] According to an embodiment of this application, after step S107, if the subsequence is the target template, the boundary array is updated using the decimal value of the subsequence, the length of the target template, and the position of the last element of the subsequence in the non-overlapping template.
[0070] In this implementation, the boundary array is updated using formula (2).
[0071] boundary[var]=point+m (2)
[0072] Wherein, boundary is the boundary array, var is the decimal value of the subsequence, point is the position of the last element of the subsequence in the non-overlapping template, and m is the length of the target template.
[0073] Figure 4 A flowchart of another matching method for non-overlapping templates for random number detection according to an example embodiment of this application is shown below. Figure 4 Taking an example, a matching method for non-overlapping templates for random number detection according to an example embodiment of this application will be described in detail.
[0074] Suppose we determine the number of occurrences of target templates 1101, 1001, 0110, and 1100 in the non-overlapping template 00110101000101011101. Note that both the target and non-overlapping templates are binary sequences.
[0075] First, in step S401, the target array target, the statistics array value, and the boundary array are initialized, and the subsequence is read.
[0076] For example, the target template is 4 bits long. According to formula (1), the lengths of the target array target, the statistical array value and the boundary array are 2^4+1=17, and the initial values are all 0.
[0077] The target array is used to store the decimal values corresponding to the target templates. Since the decimal value of target template 1101 is 13, the decimal value of target template 1001 is 9, the decimal value of target template 0110 is 6, and the decimal value of target template 0b1100 is 12, the values of the corresponding positions in the target array are updated according to step S103: target[6] = 1, target[9] = 1, target
[12] = 1, target
[13] = 1, and the remaining bits are 0.
[0078] Then, in step S403, based on the read subsequence, it is determined whether ((target[var]==1)&&(boundary[var]<=point)==1) is true. Here, var is the decimal value corresponding to the subsequence, and point is the recorded position of the last element of the current subsequence in the non-overlapping template. For example, if the subsequence length is 4, and the current point equals 9, then the subsequence is composed of the 6th, 7th, 8th, and 9th elements.
[0079] For example, take the first four bits of the non-overlapping template (0011) and store its corresponding decimal value in the variable `var`. The value of `var` is now 3. Then, use the variable `point` to record the current shift position; the value of `point` is now 4.
[0080] Since target[var] = target[3] = 0, the subsequence 0011 and the target template are not the same.
[0081] If true, proceed to step S405, updating the value of boundary[var] to (point+m) and incrementing value[var] by 1. Here, m is the length of the target template. Then proceed to step S407.
[0082] If the condition is not met, proceed to step S407.
[0083] In step S407, it is determined whether the value of point is equal to the length of the non-overlapping template.
[0084] If the value of point is not equal to the length of the non-overlapping template, proceed to step S409, increment point by 1, read the next subsequence, and then proceed to step S403.
[0085] Assuming the next bit of the non-overlapping template read is b, the value of var is updated as shown in formula (3).
[0086] var=((var&(2 m-1 -1))<<1)+b (3)
[0087] For example, after determining that the subsequence 0011 and the target template are not the same, continue reading the next bit and update the values of var and point by shifting.
[0088] According to formula (3), the value of var is (var&0x07)<<1+the value of the next bit, and the updated var=6=0b0110, point=5. At this time, it can be seen that this embodiment can retain the previously read data through shift calculation. Here, only the 5th bit is read, and the decimal value of the binary sequence composed of the 2nd to 5th bits can be obtained without rereading the 2nd to 4th bits.
[0089] Since target[var] = target[6] = 1, boundary[6] = 0, and boundary[6] <= 5 (where 5 is the value of the point variable), the resulting subsequence 0110 is a target template that meets the non-overlapping condition. Therefore, the value of value[6] is incremented by 1, and boundary[6] = point + m = 5 + 4 = 9 is updated. That is, currently, the target template 0110 appears in the 2nd to 5th positions of the non-overlapping template 00110101000101011101, so the target template 0110 can only appear in the 6th to 9th positions of the non-overlapping template. In other words, the target template 0110 cannot overlap with the non-overlapping template.
[0090] After updating the value and boundary arrays, execute step S403, repeating until all non-overlapping templates have been traversed. At this point, the value array stores the occurrence count of each target template.
[0091] according to Figure 4 The illustrated embodiment uses an array to determine whether two sequences are equivalent, employs a shifting technique to reduce the overhead of obtaining the decimal value corresponding to each subsequence, and treats "non-overlapping matching" as a boundary condition, using a boundary array to quickly determine whether this condition is met. The entire process only requires reading the non-overlapping template once to find the occurrence count of any number of target templates. In contrast, in existing technologies, because each read only searches for the occurrence count of one target template, if there are 200 target templates, 200 non-overlapping template reads are required. Therefore, this application, compared to existing technologies, does not rely on multi-core processors, GPUs, or other devices, and does not require parallel testing, thus significantly improving testing speed and enabling fast testing even on low-performance machines.
[0092] According to an embodiment of this application, the total time required to complete a non-overlapping template matching test with a template length of 9 bits on a device with a 2.4GHz CPU, a quad-core processor, and 4GB of memory for a set of 1200 random number files, each 128kb in size, is reduced from 17.96 minutes to 14 seconds, greatly reducing the overall test time.
[0093] The above description primarily focuses on the methodological aspects of the embodiments of this application. Those skilled in the art should readily recognize that, based on the operations or steps described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Those skilled in the art can implement the described functionality in different ways for each specific operation or method, and such implementations should not be considered beyond the scope of this application.
[0094] The apparatus embodiments of this application are described below. For details not described in the apparatus embodiments of this application, please refer to the method embodiments of this application.
[0095] Figure 5 A block diagram of a matching device for a non-overlapping template according to an example embodiment of this application is shown, such as Figure 5 The non-overlapping template matching device shown includes an array initialization unit 501, a target template element value determination unit 503, a non-overlapping template shifting unit 505, a subsequence judgment unit 507, and a statistical array update unit 509. Specifically, the array initialization unit 501 initializes a target template array and a statistical array based on the length of the target template; the target template element value determination unit 503 determines the element value at the corresponding position in the target template array using the target template; the non-overlapping template shifting unit 505 shifts the non-overlapping template to obtain a subsequence of the target template array; the subsequence judgment unit 507 determines whether the subsequence is the target template using the target template array; and the statistical array update unit 509 updates the statistical array based on the judgment result.
[0096] Figure 6 An electronic device according to an exemplary embodiment of this application is shown. Reference is made below. Figure 6 To describe an electronic device 200 according to this embodiment of the present application. Figure 6 The electronic device 200 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0097] like Figure 6 As shown, the electronic device 200 is presented in the form of a general-purpose computing device. The components of the electronic device 200 may include, but are not limited to: at least one processing unit 210, at least one storage unit 220, a bus 230 connecting different system components (including storage unit 220 and processing unit 210), a display unit 240, etc.
[0098] The storage unit stores program code, which can be executed by the processing unit 210 to perform the methods described in this specification according to various exemplary embodiments of this application. For example, the processing unit 210 can perform, for example... Figure 1 The method shown.
[0099] Storage unit 220 may include readable media in the form of volatile storage units, such as random access memory (RAM) 2201 and / or cache memory 2202, and may further include read-only memory (ROM) 2203.
[0100] Storage unit 220 may also include a program / utility 2204 having a set (at least one) program module 2205, such program module 2205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0101] Bus 230 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.
[0102] Electronic device 200 can also communicate with one or more external devices 300 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 200, and / or with any device that enables electronic device 200 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 250. Furthermore, electronic device 200 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 260. Network adapter 260 can communicate with other modules of electronic device 200 via bus 230. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0103] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. The technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, or network device, etc.) to execute the methods described above according to the embodiments of this application.
[0104] Software products may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example,, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections with one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0105] Computer-readable storage media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0106] Program code for performing the operations of this application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0107] The aforementioned computer-readable medium carries one or more programs, which, when executed by a device, cause the computer-readable medium to perform the aforementioned functions.
[0108] Those skilled in the art will understand that the above modules can be distributed in the device as described in the embodiments, or they can be modified accordingly and placed in one or more devices that are unique to this embodiment. The modules in the above embodiments can be combined into one module, or they can be further divided into multiple sub-modules.
[0109] According to an embodiment of this application, a computer program is proposed, including a computer program or instructions, which, when executed by a processor, can perform the methods described above.
[0110] The embodiments of this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this application. Furthermore, any changes or modifications made by those skilled in the art based on the ideas of this application, and on the specific implementation methods and application scope of this application, are all within the scope of protection of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A matching method for non-overlapping templates for random number detection, characterized in that, include: Initialize the target template array and the statistics array according to the length of the target template; Using the target template, determine the element value at the corresponding position in the target template array; Shift the non-overlapping template to obtain a subsequence of the non-overlapping template; Using the target template array, determine whether the subsequence is the target template; Update the statistical array based on the judgment result; Before using the target template array to determine whether the subsequence is the target template, the matching method further includes: Initialize the boundary array according to the length of the target template; in, Using the target template array, determining whether the subsequence is the target template includes: Record the position of the last element of the subsequence in the non-overlapping template; Calculate the decimal value of the subsequence; Using the decimal values, determine the element positions of the target template array and the element positions of the boundary array; Determine whether the value corresponding to the element position of the target template array is a preset value of the target template array, and whether the value corresponding to the element position of the boundary array is not greater than the position of the last element of the subsequence in the non-overlapping template; If the value corresponding to the element position of the target template array is a preset value of the target template array, and the value corresponding to the element position of the boundary array is not greater than the position of the last element of the subsequence in the non-overlapping template, then the subsequence is determined to be the target template.
2. The matching method according to claim 1, characterized in that, Initialize the target template array and the statistics array based on the length of the target template, including: The lengths of the target template array and the statistics array are determined based on the length of the target template.
3. The matching method according to claim 2, characterized in that, The lengths of the statistical array and the target template array are equal, and the lengths of both the target template array and the statistical array satisfy the following formula: , where m is the length of the target template, and n is the length of the statistical array and the target template array.
4. The matching method according to claim 1, characterized in that, Using the target template, determining the element value at the corresponding position in the target template array includes: Calculate the decimal value of the target template; The element positions of the target template array are determined using the decimal values. Set the value corresponding to the element position of the determined target template array to the preset value of the target template array.
5. The matching method according to claim 1, characterized in that, Using the target template array, determining whether the subsequence is the target template further includes: If the subsequence is the target template, the boundary array is updated using the decimal value of the subsequence, the length of the target template, and the position of the last element of the subsequence in the non-overlapping template.
6. The matching method according to claim 5, characterized in that, The boundary array is updated using the following formula: boundary[var] = point + m Wherein, boundary is the boundary array, var is the decimal value of the subsequence, point is the position of the last element of the subsequence in the non-overlapping template, and m is the length of the target template.
7. The matching method according to claim 1, characterized in that, After updating the statistical array based on the judgment result, the matching method further includes repeating the following steps until the last position of the non-overlapping template is reached: Shift the non-overlapping template to obtain a subsequence of the non-overlapping template; Using the target template array, determine whether the subsequence is the target template; Update the statistical array based on the judgment result.
8. A matching device for non-overlapping templates, characterized in that, The matching device is used to perform the matching method as described in any one of claims 1-7, the matching device comprising: The array initialization unit is used to initialize the target template array and the statistics array according to the length of the target template; The target template element value determination unit is used to determine the element value at the corresponding position of the target template array using the target template; A non-overlapping template shifting unit is used to shift the non-overlapping template to obtain a subsequence of the target template array; The subsequence determination unit is used to determine whether the subsequence is the target template using the target template array; The statistical array update unit updates the statistical array based on the judgment result.
9. An electronic device, comprising: processor; as well as A memory storing a computer program that, when executed by the processor, causes the processor to perform the matching method as described in any one of claims 1-7.
10. A non-transitory computer-readable storage medium having stored thereon computer-readable instructions that, when executed by a processor, cause the processor to perform the matching method as described in any one of claims 1-7.
Citation Information
Patent Citations
Random detection method of lottery industry random sequence based on comprehensive evaluation
CN107239256A
CUDA-based rapid non-overlapping template matching calculation method
CN111913798A