ID:899306
 
(See the best response by DarkCampainger.)
Code:


Problem description:Is there a way to choose random choices, for example

(prob doesnt work)

rand(1,3)
if(1)
...
if(2)
...
if(3)
...


switch(rand(1,3))

just rand(1,3) doesn't do anything.
hmm. I see. It seems to have worked. Thanks!
Best response
Here's a couple of other options:
mob/verb/Test()

// Using rand() with switch()
switch(rand(1,3))
if(1)
// 33% chance
world<<"A"
if(2)
// 33% chance
world<<"B"
if(3)
// 33% chance
world<<"C"

// Using prob() with an if-else chain
if(prob(50))
// 50% chance
world<<"A"
else if(prob(25))
// 12.5% chance (.50*.25)
world<<"B"
else if(prob(30))
// 3.75% chance (.50*.25*.30)
world<<"B"
else
// 33.75% chance (1.0 - (.5 + .125 + .0375))
world<<"C"

// Using pick() with embedded probabilities and switch()
switch( pick(20; "A",
45; "B",
35; "C") )
if("A")
// 20% chance
world<<"A"
if("B")
// 45% chance
world<<"B"
if("C")
// 35% chance
world<<"C"


The last one is probably the easiest to configure, but is a little difficult to read.

<edit>
Fixed probabilities in third example so they add up to 100
Oh wow, this is perfect! Thank you!
And I can read the last one lol. No worries.
In response to DarkCampainger (#3)
Lol, I was gonna go into all of that but found myself not wanting to provide additional information when it was un-needed for what was intended.

I'll vote yours up though, you put effort in your response.
In response to Chiwy8 (#5)
Yea, it's not too bad so long as you align the text nicely.

Also, I made a quick adjustment to it. The probabilities in pick() should add up to 100 to have the expected outcomes.