Smooth / replace random system from lootbox reward in game

46 Views Asked by At

I am creating a game and dislike the usual random system of reward a lot. Id like to drop a specific item with a chance of 1%. The usual methode would be to call a random function 0-100 and check if 1 number (in this case) is hit.

The problem here is that the player could get 2 items after another with luck or 1 item every 300 attempts with bad luck. Which is one of the most frustrating part in games.

Id like to solve this problem for my game. I could make a counter which counts from 0-100, store every attemp in a database and drop the item at 100. But this solution is from code perspective very unefficient.

Does exist a way to smooth out the randomness or does exist another system/formula to calculate 1% chance of getting reward ?

I already had an idea in mind, checking if a random number (1-2) is odd for a repeated time (6-7 ?), but im not extremly statisfied with it.

1

There are 1 best solutions below

2
On BEST ANSWER

What you're asking for is essentially non-independent random draws. There are plenty of ways to implement it, depending on the exact behaviour you want. For example:

  • Generate a list of all possible results of the draw, repeating each result proportional to its probability (e.g. 99 copies of "no reward", one copy of "reward"). Shuffle the list, and always return the next item in the list every time a draw is requested. If you reshuffle the list each time it runs out, then it's still possible to get 2 wins in a row (if position 100 was a win, and when you reshuffle it goes to position 1) or a long gap between wins, but it becomes less likely to happen multiple times.

  • Store a value representing the player's current "fortune". Every time you make a draw, compare it to this value. If the draw is higher than the fortune, you give the player no reward (or a poor reward) and you increase the fortune value. If the draw is lower than the fortune, you give the player the good reward and decrease the fortune - possibly resetting it to its original value. This is how a lot of modern poker machines and gacha games work (in Genshin Impact, for example, it's called the "pity rate"). You can tweak the specific values to allow for the average number of rewards to remain 1%, while also controlling how likely it is to have long or short gaps between rewards.