home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Basic / RNDNMGN.ZIP / RNG.BAS < prev    next >
Encoding:
BASIC Source File  |  1992-01-26  |  7.0 KB  |  336 lines

  1. ROW% = CSRLIN
  2. COL% = POS(0)
  3. CLR% = SCREEN(ROW%, COL%, 1)
  4. DIM J(16)
  5. LOOPF:
  6.   FOR X = 1 TO 16
  7.     READ J(X)
  8.       A% = J(X)
  9.       F% = A%
  10.     GOSUB MULTF:
  11.   NEXT X
  12.  
  13. GOSUB FNDBG:
  14. GOTO STRTM:
  15.  
  16. DATA 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
  17. DATA 0,16,32,48,64,80,96,112
  18. MULTF:
  19.   FOR Y = 1 TO 8
  20.     IF A% <> CLR% THEN
  21.       A% = A% + 16
  22.     END IF
  23.     IF A% = CLR% THEN
  24.       Y = 8
  25.       X = 16
  26.     END IF
  27.   NEXT Y
  28. RETURN
  29.  
  30. FNDBG:
  31. DIM K(24)
  32. LOOPB:
  33.   FOR Z = 17 TO 24
  34.     READ K(Z)
  35.     C% = K(Z)
  36.     GOSUB MULTB:
  37.   NEXT Z
  38.  
  39. MULTB:
  40.   FOR W = 1 TO 16
  41.     IF C% <> CLR% THEN
  42.       C% = C% + 1
  43.     END IF
  44.     IF C% = CLR% THEN
  45.       W = 16
  46.       Z = 24
  47.     END IF
  48.   NEXT W
  49.   IF C% >= 0 AND C% <= 15 THEN
  50.     B% = 0
  51.   ELSEIF C% >= 16 AND C% <= 31 THEN
  52.     B% = 1
  53.   ELSEIF C% >= 32 AND C% <= 47 THEN
  54.     B% = 2
  55.   ELSEIF C% >= 48 AND C% <= 63 THEN
  56.     B% = 3
  57.   ELSEIF C% >= 64 AND C% <= 79 THEN
  58.     B% = 4
  59.   ELSEIF C% >= 80 AND C% <= 95 THEN
  60.     B% = 5
  61.   ELSEIF C% >= 96 AND C% <= 111 THEN
  62.     B% = 6
  63.   ELSEIF C% >= 112 AND C% <= 127 THEN
  64.     B% = 7
  65.   END IF
  66. RETURN
  67.  
  68. STRTM:
  69. LOCATE ROW%, COL%
  70. COLOR F%, B%
  71. PRINT "Do you wish to read documentation before proceeding ? (Y/N) ";
  72. THTY:
  73. S$ = INKEY$
  74. IF S$ = "" THEN
  75.   GOTO THTY:
  76. ELSEIF S$ = "y" OR S$ = "Y" THEN
  77.   GOSUB PRTDOC:
  78. END IF
  79.  
  80. MAIN:
  81.   GOSUB CLRLIN:
  82.   D% = 0
  83.   E% = 0
  84.   L% = 0
  85.   T = 0
  86.   B = 0
  87.  
  88. GETNUMS:
  89.   LOCATE ROW%, COL%
  90.   INPUT "Enter a number to represent bottom of range : ", B
  91.   GOSUB CLRLIN:
  92.   INPUT "Enter a number to represent top of range....: ", T
  93.  
  94. COMPTB:
  95.   IF T > 0 AND B > T THEN
  96.     GOSUB CLRLIN:
  97.     PRINT "Top of rang must be greater than bottom of range."
  98.     GOSUB CHCKEY:
  99.     GOTO MAIN:
  100.   END IF
  101.  
  102. TTOOLGE:
  103.   IF T > 9999999! THEN
  104.     GOSUB CLRLIN:
  105.     PRINT "Number entered for top of range is out of processing range."
  106.     GOSUB CHCKEY:
  107.     GOTO MAIN:
  108.   END IF
  109.  
  110. BTOOLGE:
  111.   IF B > 9999999! THEN
  112.     GOSUB CLRLIN:
  113.     PRINT "Number entered for bottom of range is out of processing range."
  114.     GOSUB CHCKEY:
  115.     GOTO MAIN:
  116.   END IF
  117.  
  118. GRTR:
  119.   IF T > 0 AND B > 0 THEN
  120.     GOTO GETLENT:
  121.   END IF
  122.  
  123. GETLEN:
  124.   GOSUB CLRLIN:
  125.   INPUT "Enter number of digits for output...........: ", D%
  126.   IF T <= 0 THEN
  127.     GOTO DEFRNDNUM:
  128.   END IF
  129.  
  130. GETLENT:
  131.   IF T > 0 THEN
  132.     GOSUB FNDE:
  133.   END IF
  134.  
  135. GETLENB:
  136.   IF B > 0 THEN
  137.     GOSUB FNDL:
  138.   END IF
  139.  
  140. COMPLEN:
  141.   IF T > 0 AND D% > E% THEN
  142.     GOSUB CLRLIN:
  143.     PRINT "Number of digits for output must not excede"
  144.     PRINT "the number of digits in the top range entry."
  145.     GOSUB CHCKEY:
  146.     GOTO MAIN:
  147.   END IF
  148.  
  149. EQAL:
  150.   IF T > 0 AND D% = E% THEN
  151.     GOTO DEFRNDNUM
  152.   END IF
  153.  
  154. VARLEN:
  155.   GOSUB GETRNDNUM:
  156.   P = I
  157.   IF T > 0 AND P > E% THEN
  158.     GOTO VARLEN:
  159.   ELSEIF B > 0 AND P < L% THEN
  160.     GOTO VARLEN:
  161.   END IF
  162.   D% = P
  163.  
  164. DEFRNDNUM:
  165.   V = 0
  166.   FOR W = 0 TO (D% - 1)
  167.     GOSUB GETRNDNUM:
  168.       V = V + (I * 10 ^ W)
  169.   NEXT W
  170.   N = INT(V)
  171.  
  172. CMPRNDNUM:
  173.   IF B = 0 AND T = 0 THEN
  174.     GOTO GOODCMP:
  175.   END IF
  176.  
  177.   IF N < B THEN
  178.     GOTO DEFRNDNUM:
  179.   END IF
  180.  
  181.   IF T > 0 AND N > T THEN
  182.     GOTO DEFRNDNUM:
  183.   END IF
  184.  
  185.   IF N >= B THEN
  186.     GOTO FOTN:
  187.   ELSE
  188.     GOTO DEFRNDNUM:
  189.   END IF
  190.  
  191. FOTN:
  192.   IF T > 0 THEN
  193.     GOTO FOTW:
  194.   ELSE
  195.     GOTO GOODCMP:
  196.   END IF
  197.  
  198. FOTW:
  199.   IF N <= T THEN
  200.     GOTO GOODCMP:
  201.   END IF
  202.  
  203. GOODCMP:
  204.   PRINT N
  205.   LOCATE ROW%, COL%
  206.   PRINT "Would you like to try another set of numbers ? (Y/N) ";
  207.  
  208. FOSE:
  209.   A$ = INKEY$
  210.   IF A$ = "" THEN
  211.     GOTO FOSE:
  212.   ELSEIF A$ = "Y" OR A$ = "y" THEN
  213.     GOTO MAIN:
  214.   ELSEIF A$ = "N" OR A$ = "n" THEN
  215.     LOCATE ROW%, COL%
  216.     PRINT "Controlled Random Number Generator by J. Johnson"
  217.     PRINT "Copyright 1992 Red Moon Software                "
  218.   END IF
  219.  
  220. END
  221.  
  222. GETRNDNUM:
  223.   RANDOMIZE TIMER
  224.   R = RND(X)
  225.   F$ = STR$(R)
  226.   H = E%
  227.   IF H > 7 THEN
  228.     H = H - 6
  229.   END IF
  230.   IF H <= 1 THEN
  231.     H = H + 2
  232.   END IF
  233.   J$ = RIGHT$(F$, H)
  234.   Q$ = LEFT$(J$, 1)
  235.   I = VAL(Q$)
  236. RETURN
  237.  
  238. FNDE:
  239.   IF T <= 9 THEN
  240.     E% = 1
  241.   ELSEIF T <= 99 THEN
  242.     E% = 2
  243.   ELSEIF T <= 999 THEN
  244.     E% = 3
  245.   ELSEIF T <= 9999 THEN
  246.     E% = 4
  247.   ELSEIF T <= 99999 THEN
  248.     E% = 5
  249.   ELSEIF T <= 999999 THEN
  250.     E% = 6
  251.   ELSEIF T <= 9999999 THEN
  252.     E% = 7
  253.   END IF
  254. RETURN
  255.  
  256. FNDL:
  257.   IF B <= 9 THEN
  258.     L% = 1
  259.   ELSEIF B <= 99 THEN
  260.     L% = 2
  261.   ELSEIF B <= 999 THEN
  262.     L% = 3
  263.   ELSEIF B <= 9999 THEN
  264.     L% = 4
  265.   ELSEIF B <= 99999 THEN
  266.     L% = 5
  267.   ELSEIF B <= 999999 THEN
  268.     L% = 6
  269.   ELSEIF B <= 9999999 THEN
  270.     L% = 7
  271.   END IF
  272. RETURN
  273.  
  274. PRTDOC:
  275.   CLS
  276.   PRINT
  277.   PRINT "   This program will  generate a random number  defined by your input  to  the"
  278.   PRINT " initial  program  prompts.  The first  of which  will  ask you  for a  number"
  279.   PRINT " representing the bottom of the user defined range  (lowest number to accept)."
  280.   PRINT " The second will ask for a number  to represent the top of the range  (highest"
  281.   PRINT " number to accept).  The third will ask  for the number of digits required for"
  282.   PRINT " output  (how many digits  do you need ?).  If  you provide  input to both the"
  283.   PRINT " first and second prompts, the the third prompt will not appear."
  284.   PRINT
  285.   PRINT "    You may  wish to skip  one  of the first two prompts  to create a lower or"
  286.   PRINT " higher bound to the output.  For instance, if you wanted a three digit number"
  287.   PRINT " that is not lower than  25,  then you would answer the first prompt with  25,"
  288.   PRINT " leave the second prompt empty (press the ENTER key), and enter 3 to the third"
  289.   PRINT " prompt.  If you wanted a  2 digit number that is no higher than 80,  then you"
  290.   PRINT " would leave the first prompt empty, enter 80 to the second prompt,  and enter"
  291.   PRINT " 2 to the third prompt."
  292.   PRINT
  293.   PRINT "    To create a  hi/low range  for the  generated number,  just enter  the low"
  294.   PRINT " number at the first prompt  and the  high  number  at the  second prompt.  To"
  295.   PRINT " create any 5 digit number, leave the first 2 prompts empty and enter 5 to the"
  296.   PRINT " the third prompt."
  297.   PRINT
  298.   GOSUB CHCKEY:
  299.   CLS
  300.   PRINT
  301.   PRINT "Precauations:"
  302.   PRINT
  303.   PRINT "   - Bottom and Top of range inputs cannot excede 9,999,999."
  304.   PRINT
  305.   PRINT "   - Top of range value must be higher than the value of the bottom"
  306.   PRINT "     range."
  307.   PRINT
  308.   PRINT "   - The number of digits required for output cannot excede the"
  309.   PRINT "     number of digits in the top of range value."
  310.   PRINT
  311.   PRINT "   - Tight ranges (i.e. bottom range = 3 and top of range = 6) will"
  312.   PRINT "     require a much longer period of time to process than wide ranges"
  313.   PRINT "     (i.e. bottom of range = 120 and top of range =1000)."
  314.   PRINT ""
  315.   GOSUB CHCKEY:
  316.   CLS
  317. RETURN
  318.  
  319. CHCKEY:
  320.   PRINT "Press any key to continue...";
  321.  
  322. TNSY:
  323.   S$ = INKEY$
  324.   IF S$ = "" THEN
  325.     GOTO TNSY:
  326.   END IF
  327. RETURN
  328.  
  329. CLRLIN:
  330.   LOCATE ROW%, COL%
  331.   PRINT "                                                                               "
  332.   PRINT "                                                                               "
  333.   LOCATE ROW%, COL%
  334. RETURN
  335.  
  336.