# HP Forums

Full Version: (19c) Just an excersize - lottery numbers generator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
While playing with my recently acquired (and repaired) HP-19C I created a little program that tries to suggest you the next winning numbers for your favourite lottery. As at the same time I was testing a Lehmer PRNG for Python I wanted to check if that PRNG can be implemented on HP-19C. I used Schrage's method as described on page above.

You start the program with a seed in X on stack. You can play with various seeds like date and time of drawing, Julian date etc. Whatever you enter here may give you the big win but almost certainly will give you nothing .

After you start, the program asks you how many numbers you want to draw (max 6) and from what range. As the drawing goes on, the program checks if there are no duplicated numbers. If a number already is in temporary registers R1-R6, it drops last result and draws new. After you get the required numbers, program stops to check if you want to continue. You may use this feature to draw numbers for 5+2 or similar system lotteries. If you enter 0 program exits. R.0 is print control register. If it is 0, results are shown on screen only. Values other than 0 enables printing results.

You must additionally initiate R.0 to R.4 registers as shown below:

Code:
```                   R0  ; control register                    R1  ; temp registers for duplicate numbers check                    R2  ; temp registers for duplicate numbers check                    R3  ; temp registers for duplicate numbers check                    R4  ; temp registers for duplicate numbers check                    R5  ; temp registers for duplicate numbers check                    R6  ; temp registers for duplicate numbers check           6.0000   R7  ; scratch register          49.0000   R8  ; MM number range           1.0000   R9  ; scratch register           1.0000   R.0 ; print control register 0 – no print,       2147483647.   R.1 ; Lehmer constant M       48271.0000   R.2 ; Lehmer constant A       44488.0000   R.3 ; Lehmer constant Q        3399.0000   R.4 ; Lehmer constant R      1312360750.   R.5 ; PRNG state```

Then enter the program:

Code:
```   01 *LBL0 25 14 00 ; program start    02  ST.5    45 .5 ; store seed to R.5    03  FIX0 16 13 00    04    5        05 ; N = how many numbers to draw, default 5, max. 6    05   R/S       64 ; if other number wanted enter here    06 *LBL4 25 14 04 ; beginning of new drawing of N from MM numbers    07  STO0    45 00 ; store N to R0 and R7    08  STO7    45 07    09    0        00 ; subroutine to clear last number registers    10 *LBL3 25 14 03    11  STOi    45 12    12   DSZ    25 45    13  GTO3    14 03    14  RCL7    55 07 ; restore content of R0 register with N    15  STO0    45 00    16  RCL8    55 08 ; set MM - number range to draw    17   R/S       64    18  STO8    45 08    19  RC.0    55 .0 ; check if printing is enabled    20  X≠0?    25 51    21   SPC    25 65 ; if yes, print SPC    22 *LBL1 25 14 01 ; main program loop    23  GSB2    13 02 ; draw a number, if number returned is 0, it was    24  X=0?    25 61 ; already drawn, so repeat    25  GTO1    14 01    26   PSE    16 64 ; pause to read a number    27  STOi    45 12 ; store number to last number register    28  RC.0    55 .0 ; if printing is enabled print a number    29  X=0?    25 61    30  GTO5    14 05    31   X↕Y       11    32  PRTX       65    33 *LBL5 25 14 05 ; repeat LBL1 loop to draw N numbers    34   DSZ    25 45    35  GTO1    14 01    36    0        00 ; now check if drawing should continue    37   R/S       64 ; leave 0 to break, enter number to continue drawing    38  X>0?    25 41 ; N numbers    39  GTO4    14 04    40  FIX4 16 13 04 ; if 0 was entered, exit    41   RTN    25 13    42 *LBL2 25 14 02 ; draw a number using Lehmer PRNG    43  RC.5    55 .5    44  RC.3    55 .3    45    /        61    46   INT    16 52    47  RC.5    55 .5    48  ENT↑       21    49  ENT↑       21    50  RC.3    55 .3    51  GSB6    13 06    52  RC.2    55 .2    53    x        51    54   X↕Y       11    55  RC.4    55 .4    56    x        51    57    -        31    58  RC.1    55 .1    59   X↕Y       11    60  X<0?    25 31    61    +        41    62  ST.5    45 .5 ; store generator state in R.5    63  ENT↑       21    64  ENT↑       21    65  RCL8    55 08    66  GSB6    13 06 ; (R.5 mod R8) + 1 is a drawn number    67    1        01    68    +        41    69  RCL0    55 00 ; now check if new number is not duplicated    70  STO9    45 09 ; save R0 value to R9    71  RCL7    55 07 ; we will be searching in R1 to RN    72  STO0    45 00    73    R↓       12    74    R↓       12    75 *LBL7 25 14 07    76  RCLi    55 12    77   X↕Y       11    78  X=Y?    16 61 ; compare new number with RN … R1    79  GTO8    14 08    80   DSZ    25 45    81  GTO7    14 07    82  GTO9    14 09    83 *LBL8 25 14 08 ; if number exist return 0    84    0        00    85 *LBL9 25 14 09    86  RCL9    55 09    87  STO0    45 00 ; restore value of R0     88   X↕Y       11    89   RTN    25 13    90 *LBL6 25 14 06 ; modulo function, A mod B, requires A to be on Z    91  STO9    45 09 ; and Y stack levels and B on X    92    /        61    93   INT    16 52    94  RCL9    55 09    95    x        51    96    -        31    97   RTN    25 13```

I have also tested the program on this great HP-19C emulator.
It was a great fun for me to get familiar with programming this calc, so have fun too!

M
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :