# Coding problem: "Rolling with disadvantage"

Twine Version: 2.3.14

Hi, similar to rolling with disadvantage in D&D and other RPGs, I’m basically randomly generating 2 numbers and choosing the smaller one; I wondered if there is a neat way to do that in Sugarcube? Something like:

ChooseMin.(random(0,2), random(0,2)) → “returns the smaller of the two random numbers”

If you are trying to do it with the base SugarCube code you could do something like:

``````<<set _dice1 to random(1,6), _dice2 to random(1,6)>> <- setting the die
<<if _dice1 lt _dice2>>
<<print _dice1>>
or whatever code/text you want like <<set \$result to _dice1>>
<<elseif _dice2 lt _dice1>>
<<print _dice2>>
or whatever code/text you want
<<else>> <- if they are equal
what you would want to do in this case
<</if>>
``````

(there might be a better JavaScript code for this, probably, but I’m not good at JS )

2 Likes

ChooseMin is very close: `Math.min` should do the trick:

`<<set _roll to Math.min(random(0,2), random(0,2))>>`

(should work with more than two numbers if you want the minimum of three dice, etc.)

4 Likes

Perfect, thanks!

Just curious… are you intending to tell the player what both the rolls are?

No, it’s hidden from the player. This is to randomly determine how much a NPC likes you - +2, +1 or 0 - but I didn’t want the probabilities of the different outcomes to be even. This seemed like a neat way to create different probabilities