# Statistical control over bonus selected

This topic is 4059 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I made a small flash game where the objective is to stay alive as long as possible by moving from tile to tile. Every now and then a 'bonus' tile will appear that might add to your score or increase the time you have to move to a new tile. Currently the bonus to show is just random() * 4 whith 4 being the total number of possible bonuses. I would like more control over the frequency of certain bonuses appearing so that I can place in bonuses that are extremely rare but very good if you land on it. I assume this can be done with some sort of statistical probability table but I have difficulty adding two numbers together (not kidding) so any help would be greatly appreciated - or even a pointer in the right direction. You can check out the game to see what I mean here

##### Share on other sites
You can make this as simple or as complicated as you like. Here's a reasonably flexible, but easy-to-implement method:

For each type of bonus, decide upon

1. The minimum time allowed to pass between two occurrences of the bonus.
2. The corresponding maximum time interval.

Now when the game starts, (and each time the bonus needs to be respawned) pick a random value in the time-range, and start counting down. When sufficient time has elapsed, create the bonus tile and reset the timer with a new random value. This way, you can prevent the bonus appearing twice in quick succession, while keeping the maximum 'dry spell' reasonable. The only problem with this is that you'll never be able to have more than one instance of the bonus at once. If that's a problem, we can easily reformulate.

All that's left to do is decide on a probability distribution to fit within the bounds. Unless you have some specific requirements, a uniform distribution seems as good as any:

time_to_next_spawn = minimum_interval + r * (maximum_time - minimum_time)

where r is a random fractional number between 0 and 1.

Any good?

##### Share on other sites
Isn't that the forumla to linear interpolation?

I think I get what you mean - although it would seem that this would apply to all bonuses. What I mean is something along the lines of there is a 1 in 20 chance of getting bonus A and a 1 in 100 chance of getting bonus B etc...

So when I make the call it chooses the appropriate one. I have seen similar systems for random sound choice - again based on probability.

##### Share on other sites
You can make a list of bonuses and then shuffle it. For bonuses you want to be more common, include them more than once. The bonuses are just given out in the order they are in on the shuffled list. This also ensures that rare bonuses will eventually be given out. When you get to the end of the list, just shuffle it again and start back at the beginning. This models having a bag of bonuses, with the player drawing the bonuses out of the bag one at a time. Once a bonus is taken, it is no longer in the bag so the odds of getting the other bonuses increase.

If you just want to have straight percentages for how often a player gets each bonus, you can just do something like this:

r = random()
if r < .5 then bonus 1
else if r < .8 then bonus 2
else bonus 3

This gives a 50% chance to get bonus 1, a 30% chance to get bonus 2, and a 20% chance to get bonus 3.

##### Share on other sites
You could also use a Poisson distribution to model the number of arrivals in a given timestep while maintaining an overall average rate. This is often used to model number of people arriving in a queue, traffic models, etc.

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631719
• Total Posts
3001885
×