[futurebasic] Re: [FB] Random File List

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

From: "Phil Yates" <phil.yates@...>
Date: Tue, 31 Aug 1999 15:59:42 +0100
> 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...


1. Create an array : DIM Array$(320)

2. Put a value into each slot :

_MaxItems = 320
for a = 1 TO _MaxItems
  Array$(a) = MID$(STR$(a),2)
next a

3. Jumble them up as much as you want :

for a = 1 TO 1000
  Pointer1 = RND(_MaxItems)
  Pointer2 = RND(_MaxItems)
  swap Array$(Pointer1),Array$(Pointer2)
next a

Voila !! (French for "there's a bug here somewhere but I haven't found it
yet)

HTH

Phil