Sorting question

Jeff Massung massung at gmail.com
Thu Feb 11 00:23:12 EST 2010


Craig,

This function might help you a bit (untested):

function randomItemList pItems
   local tRandomItems
   local tIdx

   repeat until pItems is empty
      put the random of the number of items in pItems into tIdx
      get item tIdx of pItems
      put it & comma after tRandomItems
      delete item tIdx from pItems
   end repeat

   # you may want to delete the last char of tRandomItems

   return tRandomItems
end randomItemList

Jeff M.

On Wed, Feb 10, 2010 at 11:03 PM, <DunbarX at aol.com> wrote:

> If I want to randomize a string of items using the random function as a
> sortKey, say:
>
> put "1,2,3" into temp
> sort items of temp by random(3)
>
> The randomization is not nearly as effective as if I say:
>
> put "1,2,3" into temp
> sort items of temp by random(100)
>
> If you run this many times to create a list of random strings (like "3,1,2"
> and "2,1,3", etc.) the second version randomizes much better than the
> first. This is a trick that harkens back to early HC. But it occurs to me I
> never
> really understood the rationale. In fact, I don't understand the syntactic
> methodology.
>
> This does not work at all:
>
> put "1,2,3" into temp
> get random(100)
> sort items of temp by it
>
> So the random function must be invoked for each item, item by item, as the
> process progresses. As a sortKey, this seems reasonable. But how does this
> operate, and what does the larger number do so much better?
>
> Thanks in advance...
>
> Craig Newman
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



More information about the use-livecode mailing list