0
\$\begingroup\$

I've got enemies with a difficulty rating from 0 to 1. I want to generate a random reward that tends to increase as the difficulty rating rises, but still be possible to have a value anywhere in the range. Essentially, the average should increase with the difficulty, but maintain the full randomness range.

One attempt was to simply multiply a uniform random number by the difficulty, but this puts a cap on the output. What is the best approach to accomplish this?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Possible duplicate of Continuous weighted random distribution, biased toward one end \$\endgroup\$
    – Philipp
    Mar 21, 2018 at 16:25
  • \$\begingroup\$ @Philipp It's definitely similar. The reason I didn't flag it as a duplicate was because of the specific request here to have a tunable parameter to adjust the amount of bias, which isn't explicit in the earlier question (even though some of the answers do include such a parameter anyway) \$\endgroup\$
    – DMGregory
    Mar 21, 2018 at 16:51

1 Answer 1

1
\$\begingroup\$

Here's one simple method:

rarity = 1 - Pow(random(), 1 + difficultyRating * maxBias)

Here maxBias is a positive value that lets you control how skewed you want your probabilities to get.

The higher difficultyRating gets, the more of the probability space gets devoted to the top end of the rarity scale.

Example mapping with maxBias = 5

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .