[futurebasic] RE: [FB] anyone remember ... (looking for the source code)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2001 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Thu, 1 Nov 2001 15:06:08 -0500
I'll try this out when I get home but I definitely
dont get it.  If I have a list of 9 items, I can
cover all 9 items in a somewhat random order?

Lets say that I have 9 items and I randomly choose
number 7.  I could then pull item number 7 out of
the list, hoping that I never choose lucky 7 again.
Thats pretty much what i was looking for but looking
at your code I've got an idea

numberOfItems = 9

array(1) = 1
array(2) = 2
array(3) = 3
array(4) = 4
array(5) = 5
array(6) = 6
array(7) = 7
array(8) = 8
array(9) = 9

I choose random entry #7 which then gets removed 
from the list, decrement the number of items and 
all entries below get moved up.

array(1) = 1
array(2) = 2
array(3) = 3
array(4) = 4
array(5) = 5
array(6) = 6
array(7) = 8
array(8) = 9
array(9) = EMPTY (doesnt count)

DEC(numberOfEntries)

then repeat the process.  

Will this work?  

It almost seems like it would but lets say I 
have a thousand such entries.  Is it a waste 
or just a fact that I have to move all entries
below the chosen one upward to fill in the gap.

If it does work my other concern would be that
it wouldnt seem random but might be very
sequential.

Questions that have no answers until I get home
to try it out.

Thanks RC & BB


W.


-----Original Message-----
From: Bowerbird@... [mailto:Bowerbird@...]
Sent: Thursday, November 01, 2001 2:05 PM
To: futurebasic@...; Bowerbird@...
Subject: re: [FB] anyone remember ... (looking for the source code)


waverly said:
>   I'm looking for a way to "randomly" choose items from a list. 
>   Once the item has been chosen, its removed from the list

wave, it looks something like this:

   for x=1 to numberofitems
      switchwith=rnd(numberofitems)+1
      swap thevariable(x),thevariable(switchwith)
   next x

now just step through the items from 1 to numberofitems.

-bowerbird

--
To unsubscribe, send ANY message to <futurebasic-unsubscribe@...>