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... ;-)
ID:259302
Apr 8 2001, 4:48 pm
|
|
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. 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: Good idea. |
In response to Dan
|
|
While you're at it, make max() and min() work that way too! And I might add, I asked that as a feature request a way back and didn't get a response. Bad Tom. =) |
In response to Monteiro
|
|
On 5/13/01 2:13 pm Monteiro wrote:
Hi! 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)] |
I agree. That's how I would expect it to work too.
--Dan