Random but unique

Dar Scott dsc at swcp.com
Sat Jan 11 15:26:01 EST 2003


On Saturday, January 11, 2003, at 12:52 PM, tkuypers at pandora.be wrote:

> Could you explain this? Removing values is not what I need, I need 
> these
> values, or am I missing something...
>>
>> Use a copy of the variable and remove values as pulled from the
>> variable?

Off the top of my head:

-- function to return n random lines from a list
-- with no line selected more than once
function getUniqueRandomLines theList n
    local theLines, pick
    put empty into theLines
    if n > the number of lines in theList then throw "Can't get random 
lines"
    repeat for n times
       put random( the number of lines in theList) into pick
       put line pick & lineFeed after theLines
       delete line pick of theList
    end repeat
    return theLines
end if

This may not fit your exact needs, but perhaps it might inspire 
something that will.  This may have a speed problem with long lists, so 
I'm not completely happy with this.

Or did I miss something about this?

(I don't think "any" will work for the above method, unless some other 
method is used to remove the line.)

Dar Scott





More information about the use-livecode mailing list