Source code of 6.1.1 - Random number |
10 CLS ' Clear the screen 11 CLEAR ' Delete the contents of all variables 12 DEFINT I-K, M-N 13 DEFLNG L, O 14 DEFDBL D-E 15 DEFSNG F-G 16 DEFSTR R-S 20 REM Than this number further starts the program code 25 RANDOMIZE TIMER ' Assign random sequences beginning 30 I = INT((RND) * 1000) 40 M = M + 1 50 INPUT J 60 IF J < I THEN PRINT "Entered number is less than required": GOTO 40 70 IF J > I THEN PRINT "Entered number is higher than required": GOTO 40 80 PRINT "You hit after the " M; " times" 90 INPUT "Exit (Y/N)" stop$ 100 IF stop$ = "N" OR stop$ = "n" THEN GOTO 10 999 END ' Completion of the programming code 1000 REM Than this number further start sub-programs |
Random number generator language processors always generates the same sequence. To avoid always start with the same sequence of the command RANDOMIZE TIMER internal clock that uses a computer to select a random start of the sequence.
Mode of behavior command INPUT in lines 50 and 90 is not the same. What's the difference?
Instead of line 100 is better used commands that contain the keyword INKEY$ that reads keystrokes. So, it should use the DO-LOOP-UNTIL structure and become familiar with the codes that 'sends' keyboard.
How to explain the execution of line 40 M = M + 1 when the seemingly mathematically impossible.
Citing of this page: Radic, Drago. " Informatics Alphabet " Split-Croatia. {Date of access}; https://informatics.buzdo.com/file. Copyright © by Drago Radic. All rights reserved. | Disclaimer |