This is continued from my previous topic in the Beginner's forum. I'm sure that you people here know this already, but it sure seemed like a great trick to me.
Thanks!

Without a GOTO command, this seemed too difficult and I at first wrote the following:
Code: Select all
Dim long_array.b(94)
For J = 0 To 93
While long_array(J) = 0
random_number=Random(93) + 1
do_over = 0
For K=0 To J
If random_number = long_array(K)
do_over = 1
EndIf
Next K
If do_over = 0
long_array(J) = random_number
EndIf
Wend
Next J
Code: Select all
;Arrays may not be declared on the fly, but must be declared before they are called.
;Because I know that I will only be useing 94 numbers, I've used a .b, or bit array.
;The ".b" tells the program what type of array it will be -- I won't need to type it again.
Dim long_array.b(94)
;This is the part that creates a random number
;It calls a function that is found at the end of the program.
;Note my use of Repeat commands nestled in the function as a
;replacement for a GOTO command.
For J = 0 To 93
Repeat
do_over = 1
random_number=Random(93) + 1
Gosub random_match
Until do_over = 0
long_array (J) = random_number
Next J
;This is used to view the array
;It displays 25 numbers on each line.
OpenConsole()
For K=0 To 24
Print(Str(long_array(K)))
Print(" ")
Next K
PrintN("")
For K=25 To 49
Print(Str(long_array(K)))
Print(" ")
Next K
PrintN("")
For K=50 To 74
Print(Str(long_array(K)))
Print(" ")
Next K
PrintN("")
For K=74 To 93
Print(Str(long_array(K)))
Print(" ")
Next K
;My standard "end of program" text
PrintN("")
Print("Press 'Enter' to continue")
pause$=Input()
CloseConsole()
End
;random number matching function
;This is where I got my "GOTO" equivalent.
;If the random number matches a number used already, the
;function terminates early, without declaring ;do_over = 1
;Thus. the Repeat/Until loop continues to create a new
;random number and to call this function again until a unique
;number is found.
random_match:
For K=0 To J
If random_number = long_array(K)
Return
EndIf
Next K
do_over = 0
Return