home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REXXSAMP.ZIP / REXXRAND.CMD < prev    next >
OS/2 REXX Batch file  |  1989-12-05  |  3KB  |  90 lines

  1. /*   */
  2. /*   Program to generate some random numbers and store them in an array
  3.       using REXX. The numbers are first calculated and stored. Then they are
  4.       reported two at a time.
  5.  
  6.       usage: REXXRAND min_range max_range how_many
  7.       where : min_range is the lowest acceptable random number
  8.                    min_range is the highest acceptable random number
  9.                    how_many is the number of samples.
  10.  
  11.                    All 3 MUST be whole positive numbers.
  12.  
  13. */
  14. /* I refuse to argue if 0 is a positive number !!!!!!  */
  15. arg min_range max_range  how_many .
  16. /*   period at the end catches any more than 3 arguments */
  17.  
  18. rc = 0                                                                                           /* set return code */
  19. if datatype(min_range,'W') = 0                                                    /* check if it's a whow number */
  20. then do                                      /* it's an error */
  21.          say 'Min_range (' min_range ')  is not a whole number.'
  22.           rc = 1                                 /* set return code */
  23.           end
  24.  
  25. if datatype(max_range,'W') = 0                                               /* do it again for max_range */
  26. then do
  27.          say 'Max_range (' max_range ')  is not a whole number.'
  28.          rc = 1
  29.          end
  30. if datatype(how_many,'W') = 0                           /* and for how_many */    
  31. then do
  32.          say 'How_many (' how_many ')  is not a whole number.'
  33.          rc = 1
  34.          end
  35. if max_range < min_range
  36. then do
  37.          say 'Max_range (' max_range ') must be greater than Min_range (' min_range ').'
  38.          rc = 1
  39.          end
  40. if max_range < 0
  41. then do
  42.          say 'Max_range (' max_range ') must be greater than 0.'
  43.          rc = 1
  44.          end
  45. if min_range < 0
  46. then do
  47.          say 'Min_range (' min_range ') must be greater than 0.'
  48.          rc = 1
  49.          end
  50. if how_many < 0
  51. then do
  52.          say 'How_many (' how_many ') must be greater than 0.'
  53.          rc = 1
  54.          end
  55.  
  56. if rc > 0
  57.      then do
  58.            say ; say ;                                                /* 2 blank lines */    
  59.                                             /* loop thru source and display
  60.                                            the syntax stuff   */    
  61.             do line = 6 while substr(sourceline(line),1,2) <> '*/'
  62.                      say sourceline(line)
  63.                       end
  64.        return
  65.              end
  66.                                    /*   It's OK, do it */
  67.                                    /*   Use x as the subscript
  68.                                          and loop from 1 to how_many
  69.                                              and fill with random numbers
  70.                                   */            
  71. do x = 1 to how_many                        
  72.      result.x = random(min_range,max_range)                          /* x is the subscript       */
  73. end x                                   /* end of x loop   */
  74.  
  75.  
  76. say 'Show  samples in steps of 2'                                               /* start showing */
  77.  
  78.  
  79. if how_many//2 <> 0
  80.        then display_loop = how_many - 1
  81.             else display_loop = how_many
  82.  
  83. do x = 1 to display_loop  by 2                        /* 1 to how_many in steps of 2 */
  84.      Say 'Sample ' x ' was ' result.x '      Sample ' x+1 ' was ' result.x+1
  85. end x                                   /* end of loop */    
  86. if display_loop <> how_many
  87.   then Say 'Sample ' x ' was ' result.x
  88. return                                   /* exit program */
  89.  
  90.