Abstract:
A two-dimensional random number generator for use in electronic applications is constructed of a shift-register random number generator using the coefficients of a primitive polynomial of degree k to generate sequences of random binary numbers, and a second random number generator to provide an index to an array of storage locations for storing and retrieving the sequences of random binary numbers generated by the shift-register random number generator.

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The present invention generally relates to random number generators for electronic applications, and more specifically, to an improved random number generator for electronic game applications. 
     2. Description of the Prior Art 
     Many electronic devices require random number generators. In particular, in games of chance such as poker, roulette, and slot machines, randomness is critically important to ensure proper payment of winnings. 
     In considering a random number generator, there are several important and desirable characteristics. First, every possible permutation in the designated range of numbers must be obtainable. Second, the probability of a permutation appearing is the same as the probability of any other permutation. Thirdly, the occurrence of a permutation does not favor or disfavor the occurrence of any other permutation. Fourthly, it is desirable that the random number generator generates random permutations having a large period before it recycles. Lastly, it is desirable that the random number generator uses minimal hardware and has fast execution speed. 
     Random number generators of the prior art do not always have these desirable characteristics. In fact, many prior art generators do not provide every possible permutation in the designated range of numbers with equal probability, while other generators may require extensive computational hardware to carry out complex algorithms. 
     Moreover, due to the constraints associated with the register size of a computer, many random number generator algorithms are not able to generate random numbers with large periods without an increase in the complexity of the algorithm to the point where generation of uniform random numbers becomes unacceptably expensive. 
     SUMMARY OF THE INVENTION 
     It is therefore an objective of the present invention to provide a method and apparatus for generating random numbers for use in electronic applications where every possible permutation is randomly obtainable. 
     Another objective of the present invention is to provide a method and apparatus for generating random numbers for use in electronic applications where the probability of each permutation is the same as the probability of any other permutation. 
     Still another objective of the present invention is to provide a method and apparatus for generating random numbers for use in electronic applications where the occurrence of one permutation does not favor or disfavor the occurrence of any other permutation. 
     Still another objective of the present invention is to provide a method and apparatus for generating random numbers for use in electronic applications where the random numbers generated has a large period before recycling. 
     Still another objective of the present invention is to provide a method and apparatus for generating random numbers for use in electronic applications where only minimal hardware is required. 
     Still another objective of the present invention is to provide a method and apparatus for generating random numbers for use in electronic applications where the execution speed is fast. 
     Briefly, the present invention provides a random number generator for use in electronic applications where, in the preferred embodiment, a two-dimensional random number generator is constructed to include a Marsaglia mother generator for providing an index to a table of random permutations generated by a shift register generator of the present invention. 
     Note that the present invention can be used in a variety of applications and devices, even though the following description pertains to game applications. 
     An advantage of the present invention is that it provides a method and apparatus for generating random numbers wherein every possible permutation is randomly obtainable. 
     Another advantage of the present invention is that it provides a method and apparatus for generating random numbers for use in electronic applications where the probability of each permutation is the same as the probability of any other permutation. 
     Yet another advantage of the present invention is that it provides a method and apparatus for generating random numbers where the occurrence of one permutation does not favor or disfavor the occurrence of any other permutation. 
     Still another advantage of the present invention is that it provides a method and apparatus for generating random numbers where the random numbers generated has a large period recycling. 
     Still another advantage of the present invention is that it provides a method and apparatus for generating random numbers for use in electronic applications where only minimal hardware is required. 
     Still another advantage of the present invention is that it provides a method and apparatus for generating random numbers for use in electronic applications where the execution speed is fast. 
     These and other objects and advantage of the present invention will no doubt become obvious to those of ordinary skill in the art after having read the following detailed description of the preferred embodiments. 
    
    
     IN THE DRAWINGS 
     FIG. 1 is a flow chart illustrating the initialization steps for the preferred embodiment of a random number generator in accordance with the present invention. 
     FIG. 2a is a flow chart illustrating the steps in generating and using the generated random numbers in the preferred embodiment of the present invention. 
     FIG. 2b illustrates the general validation steps for a game of cards. 
     FIG. 3 is a flow chart showing the steps for generating random numbers by the shift-register generator of the present invention. 
     FIG. 4 is an illustration of a display of a game apparatus using an embodiment of the present invention. 
     FIG. 5 is an illustration of the hardware for an embodiment of the present invention. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     The preferred embodiment of a random number generator of the present invention is comprised of an array of N storage locations, a first random number generator preferably the Marsaglia mother generator, and a shift register generator of the present invention. The size of the array can be designated arbitrarily and in the preferred embodiment the array size is 251, which is the greatest prime number less than 256 (2 8 ). The number of bits in each location of the array can be designated as well. In the preferred embodiment, each element is a 64-bit unsigned integer. 
     FIG. 1 illustrates the initialization process where the array is initialized. As indicated at 10, the array is indexed from 0 to N-1 and each element of the array is set to zero. A counter, generally referred as &#34;COUNTER&#34;, is used for counting the number of elements initialized. In the next step (12), the Marsaglia mother generator generates a random index, i, in the range from 0 to N-1, which is used as an index to the array. If the value at array location array i! equals zero (20), COUNTER is increased by 1. In the next step, a shift register generator configured in accordance with the preferred embodiment of the invention is used to generate a j-bit random permutation for the particular application. Typically, the number of bits in the permutation equals the size of the array element (64 bits here). If the element at array i! does not equal zero, COUNTER is not increased and the generated permutation nevertheless is placed into array i!. Finally, if COUNTER equals N, the size of the array, all the elements of the array have been filled and the initialization process ends. If COUNTER does not equal N, there are still elements in the array with zero values and the initialization process repeats by returning to box 12 of the flow chart. 
     Note that there are many possible ways to initialize an array, and the preferred embodiment of the present invention is not limited to the initialization steps described above. 
     After the array has been initialized, referring to FIG. 2a, in operating the random number generator, a random permutation is selected from the array. In the first step, the Marsaglia generator is used to generate an array index, i, as indicated at box 30. A variable, &#34;x&#34;, is set to the permutation in array i!, and a new random permutation is generated by the shift register generator and placed into array i!. In the next step as indicated at 34, variable &#34;x&#34; is checked for validity. Whether &#34;x&#34; is valid or not depends on the application and is further explained below. If &#34;x&#34; is valid, &#34;x&#34; is returned to the calling routine and used in the particular application. If &#34;x&#34; is not valid, another random permutation is selected from the array and tested again. The process repeats until a valid random permutation is selected from the array. 
     For each particular application using the permutation represented by &#34;x&#34;, there is a different validation process. Referring to FIG. 2b, the validation process for a game of five card draw poker is illustrated. The variable &#34;x&#34; is a j-bit random permutation that can be divided into m groups of k-bits, where j equals k*m+l. The variable &#34;k&#34; represents the number of bits required to represent a card (a deck of cards having 52 cards can be represented by values from 1 to 52), the variable &#34;m&#34; represents the number of cards, and the variable &#34;l&#34; is the number of remaining bits in the j-bit unsigned integer. 
     The numbers represented by each of the k-bits must be within the desired range (e.g. 52 in a 52 card deck), otherwise x is determined to be invalid. To illustrate, in a card game using a 52-card deck where 10 cards are drawn and j equals 64 bits, six-bits (which is k) are allocated for the representation of each card number for a total of 60 bits for the 10 (which is m) cards. Thus, only 60 selected bits (usually the least significant bits) are used to create the random card numbers. 
     Since 6 bits can represent values from 0 to 63 and there are only 52 card numbers, not all the bit patterns are acceptable. A bit pattern is acceptable if the value represented by a 6-bit pattern is between 1 and 52, and this is tested by decision box 42. If all the bit patterns are not within the desired range, 52 in this case, then this is an invalid permutation and x is determined to be invalid. Moreover, the random permutation is acceptable only if all the bit patterns are different (44), meaning that no two card numbers are the same. If all the bit patterns are not different, again x is invalid. Otherwise, x is determined as a valid permutation that can be used for this particular game. 
     In another validation example for the stop-reels type of game, commonly referred to as slot machines, there may be three stop reels having 72, 70, and 70 different symbols respectively requiring 7 bits for each stop reel. Additionally, there are 5 master combination reels activated successively where only one reel is activated at any one time. Each of the master combination reels requires 5 bits to represent twenty different symbols. Since only one master combination reels is activated at any one time, only 5 bits are needed. There is a bonus round where one of three jackpots is selected, and hence requiring 2 bits. Finally, the value of the payout from the jackpot may be stepped-controlled by 4 bits. Thus, each grouping of the bits needs to be in the specified range before x is accepted as a valid permutation. Namely, each of the 3 groups of seven bits needs to be in the range from 1 to 72, 70, and 70 respectively; the 5-bit group needs to be in the range from 1 to 20; the two-bit group needs to be in the range from 1 to 3; and the group of bits for step-control must be in the specified range as well. In this example, a total of 32 bits are used. 
     Note that the shift register cannot generate a value of all zero bits. To preserve a required characteristic of the random number generator (that each possible outcome occurs exactly the same number of times as any other outcome), the validation function must be designed so that, if a value of all zero bits occurred, it would be considered invalid and discarded. For example, in a game using a deck of 52 cards, the numbers corresponding to the cards is chosen to be 1 to 52 rather than 0 to 51. If 0 to 51 had been used, then the value of all zero bits would be a valid hand, and that hand would be under-represented because the all zero bits case does not actually occur. 
     Note that although the Marsaglia mother generator is used in the preferred embodiment, it is not limited to such generator for generating indices. 
     THE MARSAGLIA &#34;MOTHER GENERATORS&#34; 
     This generator is developed by Professor Marsaglia and has been described as &#34;the Mother of all Random Number Generators&#34;. It starts with an initial seed, X, where X equals 123456. The next seed X n  is generated by the formula: X n  =672*(X n-1  MOD 1000)+(X n-1  DIV 1000), where X n-1  is the previous seed and MOD and DIV are integer operations. The random number return from the seed is simply (X n  MOD 1000). For example, 
     seed=123456 
     X n  =672*456+123=306555 returns 555 
     X n+1  =672*555+306=373266 returns 266 
     X n+2  =672*266+373=179125 returns 125 
     The formula can be carried out by SHIFT and logical AND operations. To illustrate, let X be a 32-bit integer and the formula can be rewritten as: 
     
         X.sub.n =672*(X.sub.n-1 &amp;65535)+(X.sub.n-1 &gt;&gt;16) 
    
     and returns (X n  &amp; 65535) as the random number. It has been shown that this random number generator produces a sequence of 16-bit integers with a period greater than 2 29 . 
     The period can be increased by concatenating two such generators: 
     
         X.sub.n =30903*(X.sub.n-1 &amp;65535)+(X.sub.n-1 &gt;&gt;16), 
    
     
         Y.sub.n =18000*(X.sub.n-1 &amp;65535)+(X.sub.n-1 &gt;&gt;16), 
    
     and returning ((X n  &lt;&lt;16)+Y n ). The period of this generator is greater than 2 59 . Note that the numbers 672, 30903, and 18000 are predetermined numbers of the Marsaglia generator. 
     SHIFT REGISTER GENERATOR FOR GENERATING RANDOM PERMUTATIONS 
     In accordance with the present invention, an algorithm is presented for generating all possible random permutations of random phenomena with the correct probabilities associated with these outcomes. This algorithm is based on the theory of primitive polynomials and shift register random bit generators. The computational complexity associated with the generation of N random permutations using this generator is O(N). 
     In order to simulate a random phenomenon, an algorithm must be able to generate every possible permutation where the probability of each permutation appearing is the same as the probability of any other permutation. Furthermore, the occurrence of one permutation does not favor or disfavor the occurrence of any other permutation. The shift register generator here is also referred to as a full cycle generator and the value zero is not considered to be in the set of numbers. 
     The shift register random number generator of the present invention has a large periodicity to generate uniform, independent random permutations. It is based upon using the coefficients of primitive polynomials and a shift register random number generator. Although shift register random number generators are known to be autocorrelated, the present algorithm eliminates the existence of dependence or autocorrelation between neighboring uniform random numbers without reducing the long periodicity of the generator. Furthermore, the present algorithm is computationally easy to implement and one can use pseudoregisters making both the algorithm and its implementation register-size independent. Thus the present algorithm can be implemented in an eight-bit microprocessor or in a supercomputer without any change in the sequence of random numbers produced. 
     Primitive Polynomials 
     Here, polynomials of a given degree n on a field F 2  ={0, 1} are considered. To illustrate, 
     if P 1  (x)=x 3  +x 2  +x and 
     P 2  (x)=x 4  +x 2  +1, 
     then P 1  (x)+P 2  (x)=x 4  +x 3  +x+1, 
     and the vector of the coefficients of this polynomial is (1, 1, 0, 1, 1). The code sequence of 0&#39;s and 1&#39;s corresponding to the coefficients of the polynomial represents the polynomial. Some of the properties of these types of polynomials include: every polynomial is its own additive inverse; and the sum of any two polynomials is a polynomial of the same degree. 
     A polynomial is monic if the coefficient of the highest power of x is 1. A prime polynomial is a monic polynomial which cannot be factored into a product of lower order polynomials. The monic prime polynomials of degree 0 is P=1; of degree 1 are x and x+1; of degree 2 is x 2  +x+1; and of degree 3 are x 3  +x+1 and x 3  +x 2  +1. A primitive polynomial of degree k≧1 is a prime polynomial for which f(0) is not zero, and if f(x) divides x m  -1, then m≧2 k  -1. For example, the polynomial f(x)=x 2  +x+1 is a primitive polynomial of degree k=2. It is prime because it is a monic polynomial which cannot be factored into a product of lower order polynomials. It is primitive because f(0)&lt;&gt;0 and 2 k  -1=3, where the smaller polynomial of the form x m  -1 divided by f(x) results in m=3 which is less than or equal to 2 k  -1. Polynomials x 4  -x-1 and x 64  -x 4  -x 3  -x-1 are examples of primitive polynomials of degrees 4 and 64 respectively. 
     Algorithm for Shift Register Generator 
     A way of generating random bits (not random numbers) is to start with a bit pattern of desired size and use the following algorithm described using Intel 8086 assembly language instructions: 
     mov ax, x; the unsigned number x is moved to register ax 
     shl ax, 1; shift register ax left one bit 
     jno over; jump if high bit was originally zero 
     xor a; a&#39;s binary digits are coefficients of a primitive polynomial 
     over: mov x, ax 
     The constant &#34;a&#34; represents the coefficients of the selected primitive polynomial. To illustrate the operation of this algorithm, consider a four bit binary number 1010 which is used as the seed. The polynomial x 4  -x-1 is a fourth degree primitive polynomial, which has a vector of binary digits (1, 0, 0, 1, 1). Ignoring the high order bit, the binary number formed by the bits above is 0011. In executing the algorithm above, the sequence of numbers generated by the algorithm is: 1010, 0111, 1110, 1111, 1101, 1001, 0001, 0010, 0100, 1000, 0011, 0110, 1100, 1011, 0101, and etc. The sequence of random bits generated by the above algorithm is 010111100010011. From the above sequence of random bits, one could generate the following sequence of four bit binary numbers by sequentially taking every four bits starting from the left and moving a bit at a time to the right: 0101, 1011, 0111, 1111, 1110, 1100, 1000, 0001, 0010, 0100, 1001, 0011. Note that the generation of these random numbers is extremely fast because the shift and logical-and operations are extremely fast for all computer architectures. 
     Referring to FIG. 3, the shift register generator of the present invention for generating at random all the permutations of n things chosen m at a time is described by the flow chart. First, the smallest number of bits k required to represent the number n and the number of items, m, are selected (50). For example, in a game of poker using a deck of cards and dealing 5 cards, n equals 52, m equals 5, and k is the number of bits needed to represent 52. Next, a primitive polynomial of degree &#34;n&#34;, where n is at least m*k, is looked-up, and a constant &#34;a&#34; is defined as the binary number whose bits correspond to the n low order coefficients of that primitive polynomial of degree n (52). Using the shift register described above and the constant &#34;a&#34;, a sequence of m*k (or more) bits are generated (54). Note that a m*k degree primitive polynomial has (m*k)+1 coefficients. In the preferred embodiment, the low order m*k coefficients are used. 
     Referring to FIG. 4, an application of an embodiment of the present invention is illustrated as part of a gaming apparatus 60. The apparatus includes a monitor 62 showing game information and five cards 64. The cards are generated by corresponding random numbers generated by the generator of the present invention. The display also includes a number of buttons 66 for user input. 
     FIG. 5 illustrates a hardware embodiment of the present invention in the form of a control board 70. The board includes a processor 72 such as an Intel 8088, RAM memory for storing instructions 76 as well as data 74, ROM memory 80 for storing preprogrammed data and/or instructions, a display driver 78 for driving a monitor, a bus 82 providing a communication pathway among the components, and a bus interface 84 for interacting with external inputs from the user 88 and from a programmer 86. 
     Although the present invention has been described in terms of the presently preferred embodiment, it is to be understood that such disclosure is not to be interpreted as limiting. Various alterations and modifications will no doubt become apparent to those skilled in the art after reading the above disclosure. Accordingly, it is intended that the appended claims be interpreted as covering all alterations and modifications as fall within the true spirit and scope of the invention.