ID:259302
 
It appears that to use pick(), I have to give it several arguments, one for each element in the list I want to pick from. That's nice when I know what the list will be at compile time, but what if I don't know until run time? I don't see a way to do it except put the things I'm interested in into a /list and pass that as one argument to pick(). Unfortunately, as far as I can tell, this doesn't work as I would hope (ie, pick() returns the list, not one of its elements).

Is it possible to modify pick() so that if given only one argument, which is a list, it picks a random member of that list. If given multiple lists, it should go back to the current behavior of picking one of the lists. But in this case, the following would be equivalent:

item = pick(mylist)

-or-

item = mylist[rand(1,mylist.len)]

Not a big deal at all, but it might be a little cleaner to have the first syntax available, plus I might not be the only one who first thought that pick() might work on a list too... ;-)

Is it possible to modify pick() so that if given only one argument, which is a list, it picks a random member of that list.

I agree. That's how I would expect it to work too.

--Dan
In response to Dan
On 4/9/01 3:13 pm Dan wrote:
Is it possible to modify pick() so that if given only one argument, which is a list, it picks a random member of that list.

I agree. That's how I would expect it to work too.

While you're at it, make max() and min() work that way too!

It's driven me insane, because I have some thirty lines of code that could be simplified to three.
In response to Spuzzum
On 4/9/01 6:29 pm Spuzzum wrote:
On 4/9/01 3:13 pm Dan wrote:
Is it possible to modify pick() so that if given only one argument, which is a list, it picks a random member of that list.

I agree. That's how I would expect it to work too.

While you're at it, make max() and min() work that way too!

Good idea.
In response to Dan
While you're at it, make max() and min() work that way too!

Good idea.

And I might add, I asked that as a feature request a way back and didn't get a response.

Bad Tom. =)
Hi!

Is this feature already on?

item = pick(mylist)

Thanks,

Julio
In response to Monteiro
On 5/13/01 2:13 pm Monteiro wrote:
Hi!

Is this feature already on?

item = pick(mylist)

I don't believe that works yet, but you should be able to get the same effect with:

proc/picklist(list/L)
return L[rand(1,L.len)]