Repeat Prevention

In many scenarios, you may want to prevent or reduce the repetition of consecutive item selections from your Probability List. RNGNeeds offers a flexible and powerful way to handle repeat prevention, allowing you to tailor the behavior to your specific needs.


Overview

Repeat prevention can be essential in various game mechanics, such as ensuring that the same random event doesn't occur back-to-back or that a player doesn't receive the same item repeatedly. RNGNeeds provides three methods to handle repeat prevention, each with its trade-offs between speed, bias, and the degree of repeat prevention.

Methods of Repeat Prevention

  • Spread: Eliminates all repeats, replacing them with the nearest enabled items. This method is fast but may introduce noticeable bias, especially for small lists or a low number of rolls.

  • Repick: Eliminates all repeats by re-rolling the selection. This method offers moderate speed and low bias but may slightly favor lower probability items and penalize higher probability items.

  • Shuffle: Greatly reduces repeats while preserving probabilities. This method can be potentially slow for large lists but introduces minimal to no bias. The order of picked items will be randomized.


How Does Repeat Prevention Work?

The Spread and Repick methods work during the actual selection process. Whenever an item is randomly selected twice in a row, the new selection is either spread to the nearest enabled item, or re-picked until a non-repeated item is selected. This process works when selecting a number of items at once, and since it takes Pick History into consideration, it works between consecutive selections as well.

The Shuffle method works a bit differently, as it is executed after the selection. The result of the selection is shuffled a number of times, based on the iterations you set in the inspector or in code. Shuffle cannot eliminate all repeats, but it can greatly reduce them. The upside is that the probability distribution will not change and will reflect the designed settings.


Setting up Repeat Prevention

Like most other features of RNGNeeds, Repeat Prevention is set individually for each ProbabilityList. By default, the prevention is turned off. You can enable repeat prevention in the inspector of your list by expanding the PICK section. Locate the button for choosing a Selection Method (Linear Search by default). Clicking will show a dropdown with the Repeat Prevention methods.

Repeat Prevention in Inspector

You can also define the method for preventing repeated item selections by using the PreventRepeat property:

Setting the Repeat Prevention in code

myProbabilityList.PreventRepeat = PreventRepeatMethod.Spread;

Shuffle Iterations If you choose the Shuffle method, you can specify the number of shuffle iterations used to reduce repeat selections. More iterations enhance the prevention of repeats, and the value is always constrained between 1 and 5.

Setting the Shuffle Iterations in code

myProbabilityList.ShuffleIterations = 3;

Examples

Repeat prevention is a powerful feature that can add depth, realism, and unpredictability to various aspects of your game. By ensuring that certain elements don't repeat consecutively, you can create a more engaging and immersive experience for players. Here are some inspiring examples of where repeat prevention can be applied:

  • Unit Responses: Ensuring characters don't repeat the same lines consecutively, adding realism and immersion.
  • Loot Drops: Preventing the same item from dropping consecutively, ensuring diversity in rewards.
  • Enemy Spawns: Avoiding the same enemy type from spawning repeatedly, creating dynamic combat.
  • Random Events or Encounters: Maintaining novelty by ensuring different random events.
  • Dialogue Choices in NPCs: Making interactions feel more natural by preventing repeated dialogue.
  • Music or Ambient Sound Selection: Enhancing audio by avoiding repetition of the same track.
  • Puzzle Generation: Keeping gameplay diverse by ensuring different puzzles or challenges.
  • Card Draws in Card Games: Maintaining fairness by preventing the same card from being drawn consecutively.
  • Weather Patterns: Creating realistic environments by avoiding consecutive identical weather conditions.
  • Randomized Quests or Missions: Keeping gameplay fresh by ensuring different quests or missions.
  • Skill or Ability Activation: Ensuring diversity in combat by preventing consecutive activation of the same skill.
  • Randomized Animations: Adding fluidity by avoiding the same animation from playing consecutively.

Repeat prevention may be a design choice that can add depth and variety to your game mechanics. By understanding the different methods and how to apply them, you can create engaging and unpredictable experiences for your players. Experiment with the different methods to find the one that best fits your specific needs and enjoy the creative possibilities that RNGNeeds opens up for you.