Length of random sequence in Locomotive Basic (1986)

70 Views Asked by At

I am learning BASIC and working now in GEM Locomotive BASIC (1986) on '86 Amstrad PC1512DD (8MHz, 512 ram, 5.25" 360 kb floppies) I am randomly generating numbers in a range with a program that prints numbers in loop as

PRINT;n

First, it prints a number, then adds a randomly generated value. This continues until it reaches a maximum value, then the program stops.

What I would like to do is to count up the number of outputs once the program stops at the end, not to add numbers.

For example, if line has numbers

20   100    1500    125

That should count as 4, as each is separate value rather than sum them as 1745. This is just an example, and I may have thousands of outputs.

Maybe to treat that numbers convert to strings then to count up string somehow? Any help will be much appreciated please.

2

There are 2 best solutions below

1
Jesse Sealand On BEST ANSWER

Not easy to verify this but after tracking down an Amstrad 486 CPC emulator, I was able to verify this works.

# variable  description
# NUM       The value of the current number being incremented
# NUMCOUNT  The total number of time the value has been incremented
# MAXNUM    The maximum value of the sequence
# MAXGAP    The largest possible value to randomly add to the NUM
100 NUM = 1
150 NUMCOUNT = 0

200 INPUT"
Max Number";MAXNUM
300 INPUT"
Max Gap";MAXGAP

400 NUMCOUNT=NUMCOUNT+1
500 NUM=NUM+INT(RND*MAXGAP)
600 IF NUM > MAXNUM THEN 800
700 GOTO 400

800 PRINT "TOTAL NUMBERS",NUMCOUNT
0
Liebenfiels On

Thank you very much, without your help I would not figure it out. I modified it and put under the loop:

# n- is my printed number
# t- is as similar to total 

    IF n THEN t= t+1 
    total= t  
    NEXT n 

# REM The below PRINT is after the Next n loop completes to the end

    PRINT "Total number",total

Similar to your one, but in my I don’t keep in front t=0 like you have numcount=0.

It works; just need a test with simpler scenario that I have in code.