[futurebasic] Re: [FB] Random File List

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

From: Steve Flavel <SFlavel@...>
Date: Wed, 01 Sep 1999 12:16:36 +0930
> 
> I have an alphabetic order list of file names which I need to randomize.
>
> If I have, say, 320 files, how do I create a random list of numbers from 1
> to 320 such that every number from 1 to 320 appears once and only once in
> the randomized sequence?
>
> If I use RND(320) I believe some individual numbers will be generated more
> than once...
>
Try this function that is really drawing randomly without replacement..

LOCAL FN randomList

  DIM I
  DIM finish
  DIM index
  DIM listLength
  DIM A(320)
  '-------------------------------------
  listLength=320
  finish=listLength

  FOR I = 1 TO listLength
    A(I)=I
  NEXT

  FOR I = 1 TO listLength
    index=RND(finish)
    SWAP A(index),A(finish)
    DEC(finish)
  NEXT
  '-------------------------------------

END FN
'=========================================

--
Regards

Steve:                 SFlavel@...