BBC BASIC for Windows
Programming >> BBC BASIC language >> Dim array
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1395089290

Dim array
Post by Wendell on Mar 17th, 2014, 8:48pm

num RND(10)

IS it possible to DIM "num" so that you get

EXP. num(1)=6 num(2)=5 num(3)=8 etc.


Ten deminsion with different values
Re: Dim array
Post by rtr on Mar 17th, 2014, 9:23pm

on Mar 17th, 2014, 8:48pm, Wendell wrote:
IS it possible to DIM "num" so that you get
EXP. num(1)=6 num(2)=5 num(3)=8 etc.
Ten deminsion with different values

Use the Knuth (or Fisher-Yates) shuffle:

Code:
      DIM num(10)
      FOR I% = 1 TO 10
        num(I%) = I%
      NEXT I%
      FOR I% = 10 TO 2 STEP -1
        SWAP num(I%),num(RND(I%))
      NEXT I%
      FOR I% = 1 TO 10
        PRINT "num("; I%; ") = "; num(I%)
      NEXT I% 

Richard.
Re: Dim array
Post by Wendell on Mar 17th, 2014, 9:53pm

THANKS RICHARD . YOU DON'T KNOW HOW MUCH THAT HELP..i HOPE I DON'T ANNOY YOU GUYS.WORKING ON A PROJECT WITH MY GRANDKIDS. i DON'T THINK BILL GATES WOULD BE INTERESTED IN ME YET THOUGH. BUT I AM GETTING THERE