[futurebasic] Re: [FB] Random File List

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : August 1999 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Tue, 31 Aug 99 17:24:52 -0500
>One way that I have seen this done (and I think that I've actually 
>used this method), is to have an array of 320 elements.  The elements 
>could be the names of the files.  What you can do is randomly pick 
>two of the elements and switch their positions using the SWAP 
>command.  Do this a few hundred times and your list should be quite 
>un-alphabetical.  Off the top of my head, I'm not sure how many swaps 
>would do the trick.
>Hope this helps.
>-jonathan2

Hi,

This code does _almost_ what Jonathan2 suggests, but by swapping every 
element with a randomly chosen element, it's all done in one pass.

DIM gRandomArray(320)

FOR r = 1 TO 320
  gRandomArray(r)=r
NEXT

LOCAL FN randomizeArray
  FOR r = 1 TO 320
    SWAP(gRandomArray(r),gRandomArray(RANDOM(320)
  NEXT
END FN

Using an int array makes it fast, then you can use members of this array 
as pointers to your string array.

FOR r = 1 to 320
  PRINT files$(gRandomArray(r))
NEXT

 0"0
 =J= a  y
  "