1. Field of the Invention
The present invention relates generally to random number generation. More particularly, the present invention relates to a pseudo-random number generator that generates an infinite number of random numbers without duplicates based on a much smaller user-defined subset.
2. Description of the Related Art
Randomness is not as cut-and-dried as you might think, that is, some streams of numbers are more random than others. Computers, being completely deterministic machines, are particularly bad at behaving randomly. In fact, the only true sources for random numbers involve measuring physical phenomena, such as the timing of radioactive decay, which can be distilled into purely random sequences using some mathematical tricks. Without access to physical devices, computer programs that need random numbers are forced to generate the numbers themselves. But the determinism of computers makes this algorithmically quite difficult. As a result, most programmers turn to pseudo-random numbers.
How do pseudo-random number generators work? A computer function random( ) really invokes a pseudo-random number generator. But what is a pseudo-random number generator? Suppose a request is made to generate a random number between 1 and 10, where every number has an equal probability of appearing. Ideally, a value would be generated on the range from 0 to 1 where every value will occur with equal probability, regardless of the previous value, then multiply that value by 10. Note that there are an infinite number of values between 0 and 1. Also, note that computers do not offer infinite precision.
To write code to implement something like the algorithm presented above, a pseudo-random number generator typically produces an integer on the range from 0 to N, and returns that number divided by N. The resulting number is always between 0 and 1. Subsequent calls to the generator take the integer result from the first run and pass it through a function to produce a new integer between 0 and N, and then return the new integer divided by N. That means the number of unique values returned by any pseudo-random number generator is limited by the number of integers between 0 and N.
In most common random number generators, N is 232−1 (approximately 4 billion), which is the largest value that will fit into a 32-bit number. Put another way, there are at most 4 billion possible values produced by the sort of number generator encountered most often. Actually, 4 billion numbers is not all that large.
A number known as the “seed” is provided to a pseudo-random number generator as an initial integer to pass through the function. The seed gets the ball rolling to generate a value. The output of a pseudo-random number generator contains nothing that is unpredictable. Each value returned by a pseudo-random number generator is completely determined by the previous value it returned and ultimately, the seed that started it all. If the integer used to compute any one value is known, then one can figure out every subsequent value returned from the generator.
In the end, a pseudo-random number generator is a deterministic program that produces a completely predictable series of numbers (called a stream). A well-written PRNG creates a sequence that shares many of the same properties as a sequence of real random numbers. For example:
The PRNG can generate any number in a range with equal probability.
The PRNG can produce a stream with any statistical distribution.
The stream of numbers produced by the PRNG can lack discernible patterns.
What pseudo-random number generators can not do is be unpredictable. If the seed is known, and the algorithm is known, one can easily figure out the sequence.
Thus, three problems are present in generating a list of random numbers. First, a list must be maintain to verify that duplicate numbers are not being generated; second, a check must be performed of the list for duplicates; and third, there is the overhead of reiterating the entire process many more times than the number of random numbers indicated to be attained.
These problems are exemplified when measuring random I/O performance, where a list of addresses must be maintained for the test case to traverse through and use when referencing the file. A pre-generated list of addresses will not allow the flexibility of measuring different test cases, (e.g. smaller or larger files).
Generating random numbers dynamically results in overhead that prevents the random I/O test case from reporting accurate response time and CPU consumption. Using built in pseudo-random generators like the random( ) function, does not guarantee reproducibility across operating systems.
The different aspects of the present invention provide a computer implemented method, data processing system, and computer usable code for generating random numbers. A request for a number of random numbers is received and common denominators are determined for the number of random numbers. Using the common denominators, grid dimensions are determined and a static pattern is retrieved using the grid dimensions. A list of random numbers is then generated using the static pattern and the grid dimensions. Finally, a list of random numbers is returned to a requestor.
The novel features believed characteristic of the invention are set forth in the appended claims. The invention itself, however, as well as a preferred mode of use, further objectives and advantages thereof, will best be understood by reference to the following detailed description of an illustrative embodiment when read in conjunction with the accompanying drawings, wherein:
The present invention relates to a pseudo-random number generator that generates an infinite number of random numbers without duplicates based on a much smaller user-defined subset. With reference now to the figures and in particular with reference to
With reference now to
In the depicted example, local area network (LAN) adapter 212 connects to south bridge and I/O controller hub 204 and audio adapter 216, keyboard and mouse adapter 220, modem 222, read only memory (ROM) 224, hard disk drive (HDD) 226, CD-ROM drive 230, universal serial bus (USB) ports and other communications ports 232, and PCI/PCIe devices 234 connect to south bridge and I/O controller hub 204 through bus 238 and bus 240. PCI/PCIe devices may include, for example, Ethernet adapters, add-in cards, and PC cards for notebook computers. PCI uses a card bus controller, while PCIe does not. ROM 224 may be, for example, a flash binary input/output system (BIOS). Hard disk drive 226 and CD-ROM drive 230 may use, for example, an integrated drive electronics (IDE) or serial advanced technology attachment (SATA) interface. A super I/O (SIO) device 236 may be connected to south bridge and I/O controller hub 204.
An operating system runs on processor 206 and coordinates and provides control of various components within data processing system 200 in
Instructions for the operating system, the object-oriented programming system, and applications or programs are located on storage devices, such as hard disk drive 226, and may be loaded into main memory 208 for execution by processor 206. The processes of the present invention are performed by processor 206 using computer implemented instructions, which may be located in a memory such as, for example, main memory 208, read only memory 224, or in one or more peripheral devices.
Those of ordinary skill in the art will appreciate that the hardware in
In some illustrative examples, data processing system 200 may be a personal digital assistant (PDA), which is configured with flash memory to provide non-volatile memory for storing operating system files and/or user-generated data. A bus system may be comprised of one or more buses, such as a system bus, an I/O bus and a PCI bus. Of course the bus system may be implemented using any type of communications fabric or architecture that provides for a transfer of data between different components or devices attached to the fabric or architecture. A communications unit may include one or more devices used to transmit and receive data, such as a modem or a network adapter. A memory may be, for example, main memory 208 or a cache such as found in north bridge and memory controller hub 202. A processing unit may include one or more processors or CPUs. The depicted examples in
An aspect of the present invention generates an infinite number of random numbers without duplicates based on a much smaller user-defined subset. The smaller subset is expanded to fit the target range of random numbers. The described random number generation does not require the user to maintain a list of numbers to verify for duplicates. There is a lower overhead in that a unique random number is produced every time the method is invoked, and produces reproducible results, even across different operating systems.
Based on the common denominator generated by common denominator generator 310, dimension generator 308 generates dimensions for a grid capable of generating the requested number of pseudo-random numbers. Once the dimensions of the grid are determined, a static pattern that conforms to the determined dimensions is retrieved from static patterns database 312. Static patterns database 312 contains list of static patterns. Static patterns database 312 may be any type of data structure, such as a memory or a disc. Using the static pattern retrieved from static patterns database 312, pseudo-random number generator 306 generates a list of the requested amount of pseudo-random numbers.
Returning to
In order to handle a larger range of random numbers, such as (0-47), another level of abstraction is added, which is exemplary shown as quadrants. For random number ranges that are not a multiple of the quadrant size, modification to the column and row patterns may be performed. These patterns are dynamically reduced to form a quadrant size that is a multiple of the random number address space.
Turning to
As the operation begins, the application prompts a requester through a graphical user interface for the number of random numbers needed (step 802). The application then receives the number of pseudo-random numbers as input by the requestor through the graphical user interface (step 804). The application determines if the number of random numbers requested by the requestor is a prime number (step 806). If the number is a prime number, then the number of random number needed is stored as the first number to be returned in the list of random numbers (step 808). For example, if the requestor requests 51 random numbers, 51 would be stored as the first number to be returned in the list of random numbers.
The application then proceeds to subtract 1 from the number of random numbers requested (step 810) with the operation continuing to step 812. Using the example from above, subtracting 1 from 51 would result in the number 50 being used for the remainder of the operation. If at step 806, the number or random numbers requested is not a prime number, the operation continues to step 812. At step 812, the requestor is then prompted for grid dimensions and/or a value set pattern to be used in generating the random numbers. As discussed previously, a requestor may want the same random numbers each time the application is invoked, even across different operating systems. In one inventive aspect of the present invention, reproducible results may be produced, even across different operating systems. In order to provide reproducible results to a requester, the requestor is required to provide the number of random numbers needed, but is also required to provide the dimensions of the grid and the value set pattern that was previously used in generating a list of random numbers.
At step 814, if the requestor indicates that a specific grid dimension and/or value set pattern is to be used, the operation then determines if a grid dimension is indicated by the requester (step 816) and if a specific pattern is indicated by the requester (step 818). If at either of steps 816 or 818, the requestor does not indicate one of the values, the application automatically generates a value for the missing information. The common denominator calculation is not required when a requestor defines at least one of a grid dimension or a static value set pattern, since either the grid dimension or the static value set pattern indicates the common denominators for the requested number of random numbers. The operation then proceeds to step 826, where a set of pseudo-random numbers are generated.
Returning to step 814, if the requester fails to indicate a specific grid dimension and value set pattern to be used, the operation then determines a common denominator for the number of random numbers that are to be generated (step 820). Using the common denominators generated, a grid dimension is generated (step 822) and a static pattern is retrieved based on the grid dimensions (step 824). The operation then proceeds to step 826, where a set of pseudo-random numbers are generated. As should be noted at this point, the operation using the path from 814, 816, 818, to 826 is a pseudo-random number generation path as one or more of the values is defined by a requestor. The operation using the path from 814, 820, 822, 824, to 826 is a random number generation path as none of the values are defined prior to the operation.
After the list of random numbers are generated (step 826), a random number list is returned to the requestor which includes the prime number as the first number if the requested number of random numbers needed was a prime number (step 828). Also returned to the requestor are the dimensions of the grid and the static value set pattern used to generate the list of random numbers.
Thus, the many aspects of the present invention generate an infinite number of random numbers without duplicates based on a much smaller requestor-defined subset. The smaller subset is expanded to fit the target range of random numbers. The described random number generation does not require the requestor to maintain a list of numbers to verify for duplicates. There is a lower overhead in that a unique random number is produced every time the method is invoked, and produces reproducible results, even across different operating systems.
The invention can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment containing both hardware and software elements. In a preferred embodiment, the invention is implemented in software, which includes but is not limited to firmware, resident software, microcode, etc.
Furthermore, the invention can take the form of a computer program product accessible from a computer-usable or computer-readable medium providing program code for use by or in connection with a computer or any instruction execution system. For the purposes of this description, a computer-usable or computer readable medium can be any tangible apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device.
The medium can be an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system (or apparatus or device) or a propagation medium. Examples of a computer-readable medium include a semiconductor or solid state memory, magnetic tape, a removable computer diskette, a random access memory (RAM), a read-only memory (ROM), a rigid magnetic disk and an optical disk. Current examples of optical disks include compact disk-read only memory (CD-ROM), compact disk-read/write (CD-R/W) and DVD.
A data processing system suitable for storing and/or executing program code will include at least one processor coupled directly or indirectly to memory elements through a system bus. The memory elements can include local memory employed during actual execution of the program code, bulk storage, and cache memories which provide temporary storage of at least some program code in order to reduce the number of times code must be retrieved from bulk storage during execution.
Input/output or I/O devices (including but not limited to keyboards, displays, pointing devices, etc.) can be coupled to the system either directly or through intervening I/O controllers.
Network adapters may also be coupled to the system to enable the data processing system to become coupled to other data processing systems or remote printers or storage devices through intervening private or public networks. Modems, cable modem and Ethernet cards are just a few of the currently available types of network adapters.
The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiment was chosen and described in order to best explain the principles of the invention, the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.