Randomize percentages & addition/subtraction

Is there a way to randomize the percentage of something? Or add or subtract a random number without going through a temp or hidden variable first?


  opposed_pair spirit
*rand %+ 15 %- 15

I know I can rand between 0 100 for these, but can I do a rand as a percentage?

And can I do this?

*rand spirit - 15 + 15

I’m not completely following what you are trying to do.

I think you’re trying to shortcut adding or subtracting (either a flat number of a percentage) from a variable without first passing the random result into a holding variable.

I think that under the hood, both *set and *rand do the same thing (i.e. assign a value to a variable), so you can’t mix them (e.g. *set Number_Variable (*rand Number_Variable 1 100) + 15) or something weird like that).
Also, because *rand takes specific arguments (namely the min and max), you can’t add additional logic into that.

If I have understood your intention correctly, my first question would be, why do you want to bypass the interim variable?

I was hoping there was a way to rand a percentage on something so that it doesn’t completely change it (ie- I don’t want *rand 1 3 which would change it far too much, I want to *rand either %+ 15 or %- 15 in the same line of code without getting too complicated.)

*temp spiritvariable 0
*rand spiritvariable 0 100
*set spirit - spiritvariable

Is this what you’re talking about? I’m not entirely sure what you mean but I think its this :sweat_smile:

If i understood perfectly, the amount added or substracted would be the random percent of the target variable right?

But i have a question. The random number need to be between (-15 >= random number <= +15)
And if the random number is 1…2…3…+15 the code would add that amount in percent to the chosen variable and if it’s -1…-2…-3…-15 the code would substract that amount?

Or the random number need to be only -15 or +15?

*rand food "-30" "30" is a valid expression. If you want to modify by random percentage:

*temp hp 200
*temp value 0
*temp dmg 0 -(hp *(15/100))   <<<The complicated "0 - (sum)" expression is to turn the term into a negation.
*temp heal hp *(20/100)
*rand value dmg heal

*set hp +value
This should print any value between HP -15% of it ~ HP +20% of it.

I still don’t get what this line is supposed to do.

@Jackpot1776 no, I know how to do that thankfully (thank god someone told me how awhile ago, been super helpful)

But I want it to be between -15 and 15, or between the percentages.

@Szaal I’ve never quite figured that out before, the (var *(15/100)) part.

Could you do a no-code example? I think we’re all struggling to understand what you want to achieve. Such as:

I want the ‘alertness’ stat to start at 50.
Then an event will occur and it will either increase or decrease the alertness stat by a random amount.
I want to randomly pick a percent between -15 and +15 to then apply to the alertness stat.
So, if it randomly rolls +10, it would then set alertness to (50 + 10%) = 55
Or, if it randomly rolls -10, it would then set alertness to (50 - 10%) = 45

1 Like

Below is one of the variables that I might use for this, starting at 50.

  opposed_pair lone

event happens to make you more of a loner
Then I want it to randomaly change between (this is how I would write it):

*rand lone %- 30 %- 15

where it changes to something in between -30 & -15 percent

So basically what you said @Sinnie XD

All you want is to pick a value between 15 and 30 and apply it in a fairmath operation.

You can’t write that in a single line of code. But you can do:

*temp amount 0
*rand amount 15 30
*set lone %-amount

You can write your own subroutine if that’s something you’ll be doing a lot.


If you don’t want to use fairmath (which will give you diminishing returns), this should give you what you need (you can add a cap to it to stop it going over 100, or below 0, or whatever limits you want). I’ve written into a repeatable process so you can watch it in action:

*create Loner 50
*create AttributeModifier 0
*create LastEffect ""

*label Choice
Do you want to go with them, or go on your own?

Your current Loner stat is ${Loner}.

Last choice we altered your loner stat by ${LastEffect}${AttributeModifier}%
    #Go with them (decrease loner stat)
        *rand AttributeModifier 1 15
        *set Loner - round(((Loner / 100) * AttributeModifier))
        *set LastEffect "-"
        *goto Choice      
    #Go on my own (increase loner stat)
        *rand AttributeModifier 1 15
        *set Loner + round(((Loner / 100) * AttributeModifier))
        *set LastEffect "+"
        *goto Choice
1 Like

If you’re just looking to modify spirit by something between -15 and 15:

*temp number 0

*rand number "-15" "15"
*set spirit %+ number

Thanks everyone!

1 Like

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.