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

Re: LOGO-L> Re: apl:deal porting to LOGO



On 30 Aug 98, at 17:22, Yehuda wrote:

> Tom Lynn wrote:
> 
> > Sorry to dig even further back in the list, but its taken me this long
> > to get an answer ready!  In case you've forgotten, the question was "How
> > do you select k items at random from a list?".

> <snipped>

> To select :k random letters from a word you can shuffle the given word
> and then extract its first :k letters. A possible program might be this:
> 
> 
>      to select :k :wrd :selection
>      if :k<1[op :selection]
>      op select :k-1 bf :wrd word :selection first :wrd
>      end
> 
>      to shuffle :wrd
>      if 2>count :wrd [op :wrd]
>      repeat random count :wrd[
>        make "wrd word bf :wrd first :wrd] ; NOT localmake
>      op word first :wrd shuffle bf :wrd
>      end
> 
> To select, for example, 7 random letters from chattahoocee you say:
> 
>     pr select 7 shuffle "chattahoochee "
> 
> Best Regards,
> [[Yehuda]]

Hi Yehuda.

Sorry, I should have mentioned, this was really in response to someone 
asking about which of two methods was more efficient.  One was basically 
your method (shuffle and take first k) and the other was to pick an item at 
random and remove it from the list and repeat k times.

My method is supposed to be more efficient than either of these, at least 
for large lists.  If it isn't, then it isn't my method, I just got it from 
a book :)

Tom
---------------------------------------------------------------
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