rizzlae suggests that you read this embed
There are two main ways of adding some randomness to your code. The simple way to achieve this is by using the chance of condition. This condition will only pass a specified percent of the time. The other option is to generate a random number and check if the generated number falls within a certain range.
This condition is great for making independent chances. You can combine it with an else to make sure that something happens if the condition does not pass.
chance of 50%:
give player diamond
if chance of 25%:
send "you win!" to player
else:
send "you lose!" to player```
While the chance of condition works well for simple conditions (mainly binomial probabilities), the math becomes a lot more complicated as you try to add more outcomes.
if chance of 20%:
# This will happen 20% of the time
else if chance of 50%:
# This will happen 40% of the time
else if chance of 10%:
# This will happen 4% of the time
else if chance of 50%:
# This will happen 18% of the time
else:
# This will happen 18% of the time```
See how confusing that can get?
To avoid the confusion of calculating each individual probability we can generate one random number and check if it falls within a certain range for each condition. If we generate and integer between 1 and 100 each number you add to a range will make it 1% more likely to occur.
set {_rand} to random integer between 1 and 100
if {_rand} is between 1 and 10:
# This will happen 10% of the time
else if {_rand} is between 11 and 60:
# This will happen 50% of the time
else if {_rand} is 61:
# This will happen 1% of the time
else:
# This will happen 39% of the time```