On Tuesday, Oct 5 1999, Nicolas R Cueto wrote:

> Sorry to intrude with a new subject.
>
> My understanding of "any"--as in "put any line of field 1 into
> somevariable"--is that it could lead to an item being randomly selected
> (from a list) more than once. Thus, if I used "put any" to reshuffle "1 6 24
> 32 43", one possible although unwanted result might be "6 1 6 32 6".
>
> How would I script a random function so as to prevent the same item being
> picked more than once? My solutions haven't been too pretty, and so I'm
> fishing here for something more elegant.
>
> Perhaps my understanding of "any" is incorrect?

I think your understanding of "any" is correct.  The problem is that its not
designed to do what you want to do - the random function doesn't take into
account any previous results when searching.  You need to compile a list of
the results you've already got, adding to it each time you get a result.  If
that result appears in the list, you'll need to repeat until you don't get
that item.  A better alternative might be to sort the list in advance into a
random order.  For example:

put empty into tFinalList
put card field "list" into tList --contains your list of items
repeat (the number of items in tList)
  put random(the number of items in tList) into tItemPicked
  put item tItemPicked of tList & comma after tFinalList
  delete item tItemPicked of tList
end repeat
delete last char of tFinalList
answer "The list was" && tFinalList

Regards,

Kevin

> Cheers,
>
> Nicolas R Cueto

Kevin Miller <[EMAIL PROTECTED]> <http://www.xworlds.com/>
Cross Worlds Computing, MetaCard Distributors, Custom Development.
Tel: +44 (0)131 672 2909.  Fax: +44 (0)1639 830 707.

Reply via email to