Page 1 of 1

Trouble with arrays

Posted: Sun Oct 26, 2003 10:41 pm
by Banaticus
I'm having a bit of trouble with arrays.

Code: Select all

  Dim long_array.b(94)

  Repeat
    do_over=0
    For J = 0 To 93
      random_number=Random(93) + 1
      For K=0 To J
        If random_number = long_array(K)
          do_over=1
        EndIf
      Next K
      If do_over = 0
        random_number = long_array(J)
      EndIf
    Next J
  Until do_over=0
  
  OpenConsole()
 
  For K=0 To 93
    Print(Str(long_array(K)))
    Print(" ")
  Next K
  
  PrintN("")
  Print("Press 'Enter' to continue")
  pause$=Input()
  CloseConsole()
  End
I'm trying to list the numbers from 1 to 94 in random order. But everytime I run this code it displays, "0 0 0 0 0 0 . . ." What am I doing wrong?[/code]

Posted: Sun Oct 26, 2003 11:49 pm
by Mr Tickle
You got line 12 the wrong way around is should be long_array(J) = random_number It works for me anyway ;)

How to order a singly incremented set of numbers randomly

Posted: Mon Oct 27, 2003 1:16 am
by Banaticus
Thanks! I made some changes (such as fixing the never-ending loop I created), and am posting the corrected version (including my insight into return statements nestled in If/Then loops as replacing GOTO statements) into the Tip's and Trick's forum as Replacement for GOTO command