ID:176147
 
To create a version of the pick() proc that works with associated lists. As in, list("value1"=200, "value2"=50) where value1 is four times as likely to be picked as value2... But I just can't seem to come up with any way to do this. Can anyone help?
Triste wrote:
To create a version of the pick() proc that works with associated lists. As in, list("value1"=200, "value2"=50) where value1 is four times as likely to be picked as value2... But I just can't seem to come up with any way to do this. Can anyone help?

I thought this was what you wanted, until I read the post again;
proc
AssociatedListPick(list/Thelist[0])
if(!istype(Thelist,/list)) return
var/list/associated_items = new()
for(var/T in Thelist)
associated_items += Thelist[T]
if(associated_items.len == Thelist.len)
return pick(associated_items)


But I'm sure it could easily be altered to do what you want it to. It wouldn't be safe for me to do it right now, as I am too tired to do any real efficient coding.

Sorry I couldn't help more.

Also, this belongs in Newbie Central, for you do not have a current snip of coding you need help on.

~>Volte
In response to Volte
Funny how every code problem that doesn't include code instantly belongs in Newbie Central.
In response to Triste
You don't have a code to have a problem with, so how could it be a code problem?
In response to Nadrew
Perhaps Design Philosophy would be better. :P

Newbie Central is where you ask... Newbie questions.
In response to Triste
Your new at wierd versions of the pick proc...
:P
Triste wrote:
To create a version of the pick() proc that works with associated lists. As in, list("value1"=200, "value2"=50) where value1 is four times as likely to be picked as value2... But I just can't seem to come up with any way to do this. Can anyone help?

In fact such a proc already exists.

Dream Tutor: Learn To Love Associative Lists

Lummox JR