ID:161882
 
How would I take and make it so a random variable in a random code problem could be multiple things?

Example..

var/randomfish=rand(1,32)
if(randomfish==1)

Like, that - randomfish==1.. How could I make it so that random would be more likely than the others, so I could take the 1 and add multiple numbers in a sense so that that specific fish would be more common in the fishing code than the others. (The 32 is a much higher number than the total of fish)
switch(rand(99))
if(0 to 9)
//10% chance
if(10 to 29)
//20% chance
if(30 to 59)
//30% chance
if(60 to 98)
//39% chance
if(99)
//1% chance


Though, if you can, using pick() might be a better choice:

var/fishtype = pick(/fish/carp = 100, /fish/shad = 50, /fish/death = 1)
var/fish/fish = new fishtype(usr)
usr << "You caught [fish]"
In response to Garthor
Garthor wrote:
Though, if you can, using pick() might be a better choice:

Except pick() doesn't work that way, you cannot set different probabilities for each item in a list with it, if you use a list every item has the same chance.
You can however make a new proc to do such a thing. You can find Lummox' pickweight() proc by searching.
In response to Kaioken
Not true. At least, what Garthor suggested with pick isn't impossible at all.

mob
verb
probabilitytest()
var/fishtype = pick(75; "Trout", 50; "Clad", 1; "Mermaid")
usr << "[fishtype]"


You'd replace the text strings with paths, obviously, but I tested this and it adheres to the values very well. The format is prob(P) or just P; value.
In response to Garthor
Thanks so much. I went with the first one, it worked like a charm for what I needed.


Big help, thanks guys.
In response to Devourer Of Souls
You're right, I messed up the formatting. http://www.byond.com/docs/ref/
In response to Devourer Of Souls
Devourer Of Souls wrote:
Not true.
At least, what Garthor suggested with pick isn't impossible at all.

Ah, I see. But that kinda depends on what you're referring to. I possibly got confused myself and though Garthor was referring to something like a pickweight() proc with the default pick(), since Garthor was using the associative list format but apparently forgot to encase it in the list() proc, or so it seemed. So I corrected that you cannot pass an associative list to the default pick() and have custom probabilities.
I stand corrected about what you said about pick()'s alternative format, since it is usable in this topic's situation. Note that it isn't as flexible as a pickweight() proc, though.