Lets say I have four currencies and I want to choose one at random:
Bronze, Silver, Gold, Platinum
Based on some "rating" value, I want to assign a probability to each currency for its chance to be chosen. Let's say this rating value is from 0.0 - 5.0
Now I'd like to weight the distribution towards the platinum side if my rating is higher, and weight it towards the bronze side if my rating is lower.
So a rating of 5.0 might look like:
Bronze: 0.0, Silver: 0.10, Gold: 0.30, Platinum: 0.60
And likewise a rating of 0.0 might look like:
Bronze: 0.60, Silver: 0.30, Gold: 0.10, Platinum: 0.0
A rating of 2.5 might look more evenly spread amongst the middle currencies.
I can't really think of an algorithm to handle this. How can I generate a distribution out of 100% based on some value that controls the distribution? Does anyone know where I can get started?
A trivial answer is to fit 4 straight lines to the data that you have and call it a day.
A more flexible approach is to define 4 non-negative relative weight functions in any way that you like, say bronze(r)
, silver(r)
, gold(r)
, platinum(r)
. And then you define total(r) = bronze(r) + silver(r) + gold(r)+ platinum(r)
. And now the probability of bronze is bronze(r)/total(r)
.
The advantage of this approach is that you can play around with functions like this: bronze(r) = 4 * 0.3^r
, silver(r) = 2 * 0.7^r
, gold(r) = 1
, platinum(r) = 0.1 * 1.8^r
. And now at r=0
bronze is most likely. At r=1
silver is most likely. At r=2
gold is most likely. And at r=5
platinum is most likely.
You should try a variety of functions, and settle with whatever results in your game being most playable.