[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Eliminating items randomly from a list.



I thought it would be a good idea to recap this.

The original post asked for a way to remove a random item from a list.

In my original response I made the double mistake of; one, assuming that
the list would be unique or that the order of removal didn't matter
(more on this latter) and two, not mentioning this in my reply.

George was good enough to point this out and he then supplied a routine
that used the position in the list to pick the item to be removed rather
than the item itself. His routine is (with the correction of a typo in
the item selection statement) data independent.

Now what did I mean when I said that my routine would work if the exact
order of removal doesn't matter. Let's say your simulating selecting a
marble from a bag of different colored marbles. If the bag contains 3
red, 3 blue and 3 green marbles (simulated by the list [r r r g g g b b
b] or [ r g b r g b r g b]) the odds of selecting a green marble is
1/3.  If I then select a green marble it makes no difference which green
marble I remove from the list.  In fact to talk about position in the
bag of marbles is meaningless.

So where does this leave the original questioner. The data structure and
routines used to manipulate that data depend a great deal on the
intended usage.  However as George's routine will work in either
situation it's probably best to use his routines unless there is some
overriding reason not to.

Hope this helps and clears up any confusion this discussion may have
caused. As George mentioned it's important when posting code, especially
in response to a question, to be as explicit as possible as to the
limitations and intended uses of the code and to test the code as much
as possible, especially at the extremes.


regards,


-- 
Frank Caggiano
caggiano@atlantic.net
http://www.atlantic.net/~caggiano
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home