[][src]Crate droprate

The droprate crate aims to be a drop-in solution for picking options from a weighted list of possibilities.

While naive random number generation to pick from some list of traits is pretty easy to implement as-needed, it doesn't take long to run into scenarios where this solution provides suboptimal results.

In a card game, you may want to simulate a deck of cards being shuffled, which means that the odds of each card becomes zero once it's been pulled from the deck.

Structs

FairlyRandomTable

FairlyRandomTable aims to create results which a human might create when asked to create a random sequence from a weighted table. It is human nature to generate a more evenly-distributed list of random values because we are aware of the the history of options chosen.

RandomTable

RandomTable represents a table of options and their relative weights. The odds of any option being selected is option's weight / all options' weights. This is a typical implementation of random tables in software and games as each trial runs independent of other trials which may have happened in the past. As such, it is perfectly valid for an option with 50% odds to be selected many times in a row. (It's an outcome which becomes statistically less likely to have happened, but nevertheless if you have 5 in a row, the next trial is still a 50% chance.)

Traits

ProbabilityTable