Weighted random
Picks from a list where some things are more likely than others, such as common gold and a rare crown. It also has a counter that protects players from long runs of bad luck.
When you need it
For loot, enemy spawns, random events, dialogue variety and anything where not all outcomes should be equally likely.
Say this to your AI
Use the weighted random from Spielerando for my chests: gold often, gems sometimes, a crown rarely, and a guaranteed crown after 40 chests without one.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP
Settings
- baseChance (0.05): The chance per roll before bad-luck protection starts, from 0 to 1.
- boostStart (20): The roll since the last hit from which the chance rises.
- guaranteeAt (40): The roll on which a hit is certain. Nobody ever waits longer than this.
Your AI gets the code
The finished code and math come through the Spielerando connection, so your AI can use them right away. Connect your AI
Common questions
how do i make some items rarer than others
Give each item a weight. A bigger weight comes up more often, and an item's chance is its weight divided by all the weights together. They do not need to add up to 100.
how do i pick several different random items
Do not just pick twice and hope, since you can get the same one again. The recipe picks several by weight in one go, and none of them repeat.
how do i stop players from never getting the rare drop
Count the misses in a row and raise the chance the longer it goes on, up to a guarantee. Nobody can go past that number, however unlucky.