Spielerando

Odds and randomness

Learning paths through this topic

Wandering enemies pile up at the ends of their platform

An enemy that takes random steps along a ledge should spend about as much time in the middle as at the edges. The common fix of cutting the position off at the border makes them stand at the border far too often. There is a way to turn at the edge that keeps them evenly spread.

An enemy that notices you at half a chance per second reacts faster on fast screens

Rolling a chance every frame ties the odds to the frame rate, so the same game plays differently on a fast monitor. The fix is a conversion, and it also decides what happens after a lag spike, where the obvious scaling gives answers above one.

Pick a random living enemy without building a list every frame

Games often need one random thing out of those that fit a condition, such as one enemy in range or one free spawn point. Building a filtered list each time wastes work, and picking a random index first can land on something that does not fit. One walk over the items does it fairly.

Choose a squad of different enemy types by weight, with no type twice

Drawing from a weighted list until you have enough different ones is slow and skews the odds when the list is short. There is a way to give every type one random score and keep the best few, so the likelier types are favoured exactly as the weights say.

How many tries does a rare drop really take when luck gets a boost over time?

A drop that gets more likely after every miss feels fair, but the real average cost is hard to guess and often much lower than the printed chance suggests. This entry shows how to compute what players actually pay before you ship it.

Poison does a random bit of harm each turn: how late can the cure come?

With random damage each turn, the average says the player dies on a certain turn, yet some die earlier and some much later, and a warning timer built on the average is wrong both ways. This shows the real chance of dying by each turn and how to set an honest deadline.

When should an explorer turn back with the loot instead of going one step further?

Every step deeper pays more but risks losing everything, and players decide by feeling while the computer-controlled helper just stops at a fixed depth. This shows the exact point where one more step stops being worth it, and what it means for the rewards you set.

Will the rain barrel run dry before the next storm, with overflow wasting water?

Water that arrives by random rain and leaves by steady use, with a barrel that overflows when full, is hard to judge by feel, and a bigger barrel helps less than players think. This shows how to compute the chance of running short during a stretch of days.

Random gaps in a platformer must never be wider than the jump can cross

A generator that picks gap widths freely will sooner or later make one that cannot be crossed, especially when the far side is higher than the take-off point. The maximum depends on more than speed. Here is the full set of ingredients and a margin that keeps it fair.

When a one-time treasure is found, the chance of other rare drops should not creep up

Items that can be found only once must leave the loot table, yet removing them in the obvious way quietly makes everything else more likely, so the late game showers the player with rares. A two-step pick keeps the rate where you set it.

A room's loot changes every time the player leaves and comes back

Generated rooms should look the same on a second visit, yet storing every room is heavy. The room can be rebuilt from the run's seed and its place, if the two are mixed carefully. A common shortcut lets different rooms share a seed without anyone noticing.

Hide exactly five chests in a hundred spots without two landing together

Rolling a spot for each chest sometimes puts two in the same place, and the usual fix of rolling again makes the cost unpredictable and the result slightly tilted. This shows a method that always takes exactly as many random numbers as chests and treats every combination equally.