[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Everything about COBOL
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
  Sorting in REXX: The Bubble Sort
  REXX Password Generator
  Using REXX to capture displayed output of TSO command
  Count records in REXX
  REXX program to calculate present value of money
  REXX function to format a number in currency format
  REXX function to produce a fixed-length number
  REXX program to produce lottery numbers
  REXX: what does your phone number spell?
  REXX Practice Problems.
  Just Enough REXX Tutorial
  Setting up to Execute REXX Programs on TSO/ISPF
  How to execute a REXX program
  REXX Boolean operators
  Comparison of CLIST language and REXX
  REXX Comparison operators
  REXX Debugging: the TRACE verb
  Using REXX OUTTRAP
  Reserved REXX Variables
  Executing REXX through JCL.
  Writing ISPF Edit Macros in REXX
  REXX program to unload a PDS
  REXX book: The REXX Language on TSO
  REXX Functions Book
  QMF Procedures Written in REXX
  Using REXX Subroutines with the QMF Calc panel
  REXX error codes (RC)
  REXX programming language manuals
  Books on REXX programming
  The REXX Files
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > REXX   > REXX Lottery Numbers

REXX program to produce 6 lottery numbers

This illustrates terminal dialogue, RANDOM function, looping.
/*REXX program Lottery
   will work on all platforms: TSO, CMS, OS/2
   Displays 6 unique random numbers between 1 and 40
*/

Number. = ""    /* clear array first */
Have_6_unique = "NO"

I = 0 /* zero out index */
Do until Have_6_unique = "YES"
    Call Get_one_unique
End
/*call showem (for debug)*/
Call Sortem
Call Showem
Call Credits
Exit

Get_one_unique:
Call Getrand
Call Is_rand_new
If Rand_is_new = "YES"
then                                              
  do  /* store the rand number in the array (else do absolutely nothing) */
    i = i + 1  
    number.i = rand                               
    if i = 6 then have_6_unique = "YES"           
  end                                             
Return /*get one unique*/
                                       
Is_rand_new:
Rand_is_new = "YES"
Do I1 = 1 to 6  /* check all 6 elements to see if rand number there */
   if number.I1  = rand    /* its there */
   then                                                                 
      do                                                                
        rand_is_new = "NO"                                              
        leave                                                           
      end                                                               
End I1
Return /*is rand new*/
                                                                        
Sortem:   /* classical bubble sort */
Do L = 1 to (6-1)
   Do M = 1 to (6-1)
      M_plus1 = M + 1
      If Number.m > Number.M_plus1 then Call Flipem
   end M
 end L
Return /*sortem*/
 
                                                                 
Showem:
say ""                                         
                                                               
Final = ""
Do K = 1 to 6
   Final = Final Number.k
End
Say final
Return /*showem*/
                                                                   
                            
Flipem:
Temp = Number.m
Number.m = number.m_plus1
Number.m_plus1 = temp
Return /*flipem*/

Getrand:
Rand = Random(1,40)
Return /*getrand*/

Credits:
Parse Source Op_system .
If Op_system = "OS/2"
then
   do
      Function_to_load = "Syssleep"
      Call rxfuncadd function_to_load,'rexxutil',,
          function_to_load
      Call Syssleep 2
End /* for OS2*/

say
say

Return /* credits */

Learn how to use all the features of REXX: REXX Programming Book for TSO (published 2012)

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |