How can I generate a pseudo-random number (preferably in Lua), where the generator has a higher probability of giving small numbers?
In my case, I want to give a random score in a game, where it’s common to obtain the lower scores, but higher ones appear rarely.
I’ve seen weighted random number generators that use a table, but it doesn’t fit my plan. I just want to specify the minimum (0) the maximum (variable) and ensure most numbers stay low.
I am sure this is possible with a simple mathematical operation, but I cannot remember which one it was. Like to filter the regular output of math.random, no need for a really random generator.
This may not be what you’re looking for, since it’s not a smoothly biased bell curve, but why not create two steps? Define a probability of getting a lower-range score and if you match it, your range is the lower range. Otherwise, your range is from the top of the low range to the end of the high range.
The net effect is that you’d usually get a low score, but sometimes you’d get high scores. I bet it would look pretty good, and is very simple.
What do you think?