File generation method, device and computer-readable storage medium
By using random numbers to fill the identification block and data block when generating the test file, and determining the value of the unfilled position based on the last filled value and incremental random numbers, the problem of low-efficiency test file generation in the prior art is solved, and more efficient file generation and testing efficiency is achieved.
Patent Information
- Application Number
- CN201911289885.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-16
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2039-12-16
AI Technical Summary
The prior art is less efficient when generating test files, resulting in less testing efficiency. The first method is easy to compress due to the large amount of duplicate data in the file; the second method generates random numbers for a long time and has low performance.
The test file is generated by filling the randomly generated identification block random numbers into the identification block of the file to be generated, and for each position in the data block, the value of the unfilled position is determined based on the last filled value and the increment random number, to determine the value of the unfilled position.
The generated test files have different data blocks, and the internal regularity is weak, making them difficult to compress. At the same time, the speed of file generation is improved and the efficiency of test files generation and testing.
Smart Images

Figure CN112988556B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and in particular to a file generation method, device and computer-readable storage medium. Background Art
[0002] At present, when using a test tool to test storage functions and computer performance, it is necessary to generate a test file. The relevant technology mainly uses two generation methods. The first method is to use the same data to fill each position in the file, for example, fill them with 0. The second method is to generate random numbers for each position of the file so that they can be filled with random numbers. Summary of the invention
[0003] After analysis, the inventor found that the first method can realize the rapid generation of test files. However, due to the presence of a large amount of duplicate data in the file, it is easy to be compressed to a large extent, making it unsuitable for testing scenarios such as read-write performance and reconstruction performance. The second method is not easy to be compressed or the compression is relatively small, but the process of generating random numbers is very time-consuming, so this method of generating test files has relatively low performance. Therefore, the test file generation efficiency of the related technology is low, which will also affect the test efficiency.
[0004] A technical problem to be solved by the embodiments of the present invention is: how to improve the test file generation efficiency and the test efficiency.
[0005] According to a first aspect of some embodiments of the present invention, a file generation method is provided, comprising: filling a randomly generated identification block random number into an identification block of a file to be generated; for each of one or more data blocks to be filled in the file to be generated, randomly generating a seed random number and an incremental random number corresponding to the data block; filling the seed random number into a position of the corresponding data block; for each unfilled position in the data block, determining the value of the unfilled position according to the last filled value in the data block and the incremental random number.
[0006] In some embodiments, determining the value of the unfilled position according to the last filled value in the data block and the incremental random number includes: determining the sum of the last filled value in the data block and the incremental random number as the value of the unfilled position.
[0007] In some embodiments, the seed random number is filled into the first position of the corresponding data block; for each unfilled position in the data block, the value of the unfilled position is determined in turn based on the last filled value in the data block and the incremental random number until the last position of the data block is filled.
[0008] In some embodiments, determining the value of an unfilled position based on a last filled value in a data block and an incremental random number includes: determining the value of the unfilled position as the sum of the product of the last filled value in the data block and the incremental random number and the identifier of the last filled position.
[0009] In some embodiments, when the value of the unfilled position is greater than a preset range, at least one of a seed random number and an incremental random number corresponding to the corresponding data block is regenerated.
[0010] In some embodiments, filling the randomly generated identification block random number into the identification block of the to-be-generated file includes: determining a value range of the identification block random number according to the number of bytes of the identification block; generating a random number within the value range as the identification block random number, and filling it into the identification block of the to-be-generated file.
[0011] In some embodiments, the incremental random number is a non-zero integer.
[0012] In some embodiments, each location of the data block is one byte in size.
[0013] According to a second aspect of some embodiments of the present invention, there is provided a file generating device, comprising: an identification block filling module, configured to fill a randomly generated identification block random number into an identification block of a file to be generated; a generating module, configured to randomly generate a seed random number and an incremental random number corresponding to each of one or more data blocks to be filled in the file to be generated; a data block filling module, configured to fill the seed random number into a position of a corresponding data block; and, for each unfilled position in the data block, determining the value of the unfilled position according to the value last filled in the data block and the incremental random number.
[0014] According to a third aspect of some embodiments of the present invention, there is provided a file generating device, comprising: a memory; and a processor coupled to the memory, wherein the processor is configured to execute any one of the aforementioned file generating methods based on instructions stored in the memory.
[0015] According to a fourth aspect of some embodiments of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which implements any one of the aforementioned file generation methods when executed by a processor.
[0016] Some embodiments of the above invention have the following advantages or beneficial effects: since each data block corresponds to a seed random number, the different data blocks of the generated test file are irregular, and the regularity within the data block is weak, so while the generated test file is difficult to be compressed, the speed of file generation is increased. Therefore, the efficiency of test file generation and test efficiency are improved.
[0017] Further features and advantages of the present invention will become apparent from the following detailed description of exemplary embodiments of the present invention with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0019] Figure 1 A schematic flow chart of a file generation method according to some embodiments of the present invention is shown.
[0020] Figure 2 A schematic structural diagram of a file generating device according to some embodiments of the present invention is shown.
[0021] Figure 3 A schematic structural diagram of a file generating device according to some other embodiments of the present invention is shown.
[0022] Figure 4 A schematic structural diagram of a file generating device according to some further embodiments of the present invention is shown. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is by no means intended to limit the present invention and its application or use. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] The relative arrangement of components and steps, the numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless specifically stated otherwise.
[0025] At the same time, it should be understood that for the convenience of description, the sizes of the various parts shown in the drawings are not drawn according to the actual proportional relationship.
[0026] Technologies, methods, and apparatus known to ordinary technicians in the relevant field may not be discussed in detail, but where appropriate, such technologies, methods, and apparatus should be considered part of the authorization specification.
[0027] In all examples shown and discussed herein, any specific values should be interpreted as merely exemplary and not as limiting. Therefore, other examples of the exemplary embodiments may have different values.
[0028] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0029] Figure 1 FIG. 1 is a flow chart showing a method for generating a file according to some embodiments of the present invention. Figure 1 As shown, the file generation method of this embodiment includes steps S102 to S108.
[0030] In step S102, the randomly generated identification block random number is filled into the identification block of the file to be generated.
[0031] The embodiment of the present invention divides the test file into two types: identification blocks and data blocks. Each test file includes an identification block and one or more data blocks.
[0032] The identification block is used to distinguish different files when generating smaller files. The identification block is located before the data block, so that the identification block includes the first byte of the test file and several bytes thereafter.
[0033] In some embodiments, the value range of the identification block random number is determined according to the number of bytes of the identification block; a random number is generated within the value range as the identification block random number and filled into the identification block of the file to be generated.
[0034] For example, if the identification block consists of 4 bytes, you can use 0 to 2 32 The random number between fills the identification block. At this time, the probability that the identification blocks of any two different test files are the same is 1 / 4294967296, which is very low, so different test files can be distinguished.
[0035] In step S104, for each of the one or more data blocks to be filled in the to-be-generated file, a seed random number and an incremental random number corresponding to the data block are randomly generated. The seed random number may be, for example, 1 byte.
[0036] In step S106, the seed random number is filled into a position of the corresponding data block.
[0037] In step S108, for each unfilled position in the data block, the value of the unfilled position is determined according to the value filled last time in the data block and the incremental random number.
[0038] Compared with the method of filling all random numbers, the method of determining the values of other positions based on the filled values and incremental random numbers is more computationally efficient.
[0039] For example, the last filled value in the data block and the incremental random number can be added to obtain the filled content. For example, the addition can be performed directly or the incremental random number can be multiplied by a certain multiple and then summed. The amount of calculation for the addition operation is very small, so the calculation efficiency can be improved.
[0040] In some embodiments, the incremental random number is a non-zero integer, that is, it can be a positive integer or a negative integer.
[0041] Since each data block corresponds to a seed random number, the different data blocks of the generated test file are irregular, and the regularity within the data block is weak, so while making the generated test file difficult to compress, the speed of file generation is increased. Therefore, the efficiency of test file generation and test efficiency is improved.
[0042] Two methods for determining data in a data block are described below by way of example.
[0043] In some embodiments, for each unfilled position in the data block, the sum of the last filled value in the data block and the incremental random number is determined as the value of the unfilled position. The filling order can be filled from the first position to the last position, or filled in other orders according to a preset rule.
[0044] The specific method of filling in order from the first position to the last position is: fill the seed random number into the first position of the corresponding data block; for each unfilled position in the data block, determine the value of the unfilled position according to the last filled value in the data block and the incremental random number, until the last position of the data block is filled.
[0045] For example, fill the seed random number into the first position of the data block; then fill the seed random number, that is, the sum of the value of the first position and the incremental random number into the second position; next, fill the sum of the value of the second position and the incremental random number into the third position... and so on, until the last position in the data block, such as the 256th position. Repeat the above process for each data block until all data blocks of the test file are filled.
[0046] When the sequential filling from the first position to the last position is adopted, the filling value of each position can also be determined by a high-order increment. In some embodiments, the value of the unfilled position is determined as the sum of the value of the last filling in the data block and the product of the incremental random number and the identifier of the position of the last filling.
[0047] For example, fill the seed random number into the first position of the data block; then fill the seed random number, that is, the sum of the value of the first position and the incremental random number into the second position; next, fill the sum of the value of the second position and 2 times the incremental random number into the third position, and then fill the sum of the value of the third position and 3 times the incremental random number into the fourth position... and so on, until the last position in the data block. Repeat the above process for each data block until all data blocks of the test file are filled.
[0048] If the incremental random number is a positive number, the data filled in the data block will gradually increase. In extreme cases, the calculated filling value will exceed the numerical range that the computer can bear. In some embodiments, when the value of the unfilled position is greater than the preset range, at least one of the seed random number and the incremental random number corresponding to the corresponding data block is regenerated. This can avoid errors in the test file generation process, ensure the availability of the test file, and improve the test efficiency.
[0049] Reference below Figure 2 An embodiment of a document generating device according to the present invention is described.
[0050] Figure 2 FIG. 2 shows a schematic diagram of the structure of a file generating device according to some embodiments of the present invention. Figure 2 As shown, the file generation device 20 of this embodiment includes: an identification block filling module 210, configured to fill the randomly generated identification block random number into the identification block of the file to be generated; a generation module 220, configured to randomly generate a seed random number and an incremental random number corresponding to each of the one or more data blocks to be filled in the file to be generated; a data block filling module 230, configured to fill the seed random number into a position of the corresponding data block; and, for each unfilled position in the data block, determine the value of the unfilled position according to the value of the last filling in the data block and the incremental random number.
[0051] In some embodiments, the data block filling module 230 is further configured to determine the sum of the last filled value in the data block and the incremental random number as the value of the unfilled position.
[0052] In some embodiments, the data block filling module 230 is further configured to fill the seed random number into the first position of the corresponding data block; for each unfilled position in the data block, the value of the unfilled position is determined in turn based on the last filled value in the data block and the incremental random number until the last position of the data block is filled.
[0053] In some embodiments, the data block filling module 230 is further configured to determine the value of the unfilled position as the sum of the value of the last filling in the data block and the product of the incremental random number and the identifier of the last filled position.
[0054] In some embodiments, the generation module 220 is further configured to regenerate at least one of a seed random number and an incremental random number corresponding to a corresponding data block when the value of an unfilled position is greater than a preset range.
[0055] In some embodiments, the identification block filling module 210 is configured to determine the value range of the identification block random number according to the number of bytes of the identification block; generate a random number within the value range as the identification block random number, and fill it into the identification block of the file to be generated.
[0056] In some embodiments, the incremental random number is a non-zero integer.
[0057] In some embodiments, each location of the data block is one byte in size.
[0058] Figure 3 FIG. 2 shows a schematic diagram of the structure of a file generating device according to some other embodiments of the present invention. Figure 3 As shown, the file generating device 30 of this embodiment includes: a memory 310 and a processor 320 coupled to the memory 310 , and the processor 320 is configured to execute the file generating method in any one of the aforementioned embodiments based on the instructions stored in the memory 310 .
[0059] The memory 310 may include, for example, a system memory, a fixed non-volatile storage medium, etc. The system memory may store, for example, an operating system, an application program, a boot loader, and other programs.
[0060] Figure 4 FIG. 2 shows a schematic diagram of the structure of a file generating device according to some other embodiments of the present invention. Figure 4 As shown, the file generation device 40 of this embodiment includes: a memory 410 and a processor 420, and may also include an input / output interface 430, a network interface 440, a storage interface 450, etc. These interfaces 430, 440, 450 and the memory 410 and the processor 420 may be connected, for example, via a bus 460. Among them, the input / output interface 430 provides a connection interface for input / output devices such as a display, a mouse, a keyboard, and a touch screen. The network interface 440 provides a connection interface for various networked devices. The storage interface 450 provides a connection interface for external storage devices such as SD cards and USB flash drives.
[0061] An embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, wherein the program implements any of the aforementioned file generation methods when executed by a processor.
[0062] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable non-transient storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0063] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0064] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0065] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0066] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A file generation method, comprising: Filling the randomly generated identification block random number into the identification block of the to-be-generated file, wherein the to-be-generated file is a test file, including an identification block and one or more data blocks; For each of the one or more data blocks to be filled in the to-be-generated file, randomly generate a seed random number and an incremental random number corresponding to the data block; Fill the seed random number into a position of a corresponding data block; For each unfilled position in the data block, the value of the unfilled position is determined according to the value last filled in the data block and the incremental random number.
2. The file generation method according to claim 1, wherein: Determining the value of the unfilled position according to the last filled value in the data block and the incremental random number includes: The sum of the last filled value in the data block and the incremental random number is determined as the value of the unfilled position.
3. The file generation method according to claim 1, wherein: Fill the seed random number into the first position of the corresponding data block; For each unfilled position in the data block, the value of the unfilled position is determined in turn according to the value last filled in the data block and the incremental random number until the last position of the data block is filled.
4. The file generation method according to claim 3, wherein: Determining the value of the unfilled position according to the last filled value in the data block and the incremental random number includes: The sum of the value filled last time in the data block and the product of the incremental random number and the identifier of the position filled last time is determined as the value of the unfilled position.
5. The file generation method according to any one of claims 1 to 4, wherein: When the value of the unfilled position is greater than a preset range, at least one of a seed random number and an incremental random number corresponding to the corresponding data block is regenerated.
6. The file generation method according to claim 1, wherein: The step of filling the randomly generated identification block random number into the identification block of the to-be-generated file comprises: Determine the value range of the random number of the identification block according to the number of bytes of the identification block; A random number is generated within the value range as the identification block random number, and is filled into the identification block of the file to be generated.
7. The file generation method according to claim 1, wherein: The incremental random number is a non-zero integer.
8. The file generation method according to claim 1, wherein: Each location in the data block is one byte in size.
9. A file generating device, comprising: An identification block filling module is configured to fill the randomly generated identification block random number into the identification block of the to-be-generated file, wherein the to-be-generated file is a test file, including an identification block and one or more data blocks; A generating module, configured to randomly generate a seed random number and an incremental random number corresponding to each of the one or more data blocks to be filled in the file to be generated; A data block filling module is configured to fill the seed random number into a position of a corresponding data block; And, for each unfilled position in the data block, the value of the unfilled position is determined according to the value last filled in the data block and the incremental random number.
10. A file generating device, comprising: Memory; as well as A processor coupled to the memory, the processor being configured to execute the file generation method according to any one of claims 1 to 8 based on instructions stored in the memory.
11. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the file generation method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Method for generating random number
CN101038541A
Method and device for generating pseudo-random number seeds and pseudo-random numbers
CN103092566A