Skip to main content

Blind Bag

A BlindBag<T> is an unordered collection of items of type T, each of which has a weight assigned. A Blind Bag allows to randomly pick one (or more) of those items and the chance of picking any of those items depends on their weight.

In the Inspector, a Blind Bag is a list of items and relative weights.

Blind Bag Inspector

By default it uses an automatic seed, which changes every time the game is started, but by disabling the Automatic Seed flag, it's possible to supply a specific value to enable a repeatable behavior between executions.

tip

The Blind Bad Rebalance Button 'rebalance' button automatically sets all weights to 1.

Pick Items

A Blind Bag exposes many overloads to pick single or multiple items.

MethodDescription
Pick()Returns a random item.
Pick(int count)Returns an IEnumerable containing count random elements. They can be repeated.
Pick(T[] destination, int startIndex)Picks multiple random elements (they can be repeated) and put them inside the destination buffer, starting from startIndex and filling it completely. Returns the number of items placed in the destination buffer. There are variations of this method accepting a Span as a destination buffer as well as overloads to specify the expected/maximum count of items to pick.
PickDistinct(T[] destination, int startIndex)Picks multiple distinct random elements and put them inside the destination buffer, starting from startIndex and trying to fill it completely. Returns the number of items placed in the destination buffer (could be less than destination.Length - startIndex.) There are variations of this method accepting a Span as a destination buffer as well as overloads to specify the expected/maximum count of items to pick.

See the Reference page for more information.