> For the complete documentation index, see [llms.txt](https://pahutyakv.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pahutyakv.gitbook.io/docs/randomly/weighted-list.md).

# Weighted List

`WeightedList<T>` and `CurveWeightedList<T>` are Unity-friendly, serializable collections (`[Serializable]`) designed for effortless configuration directly inside the Unity Inspector. They wrap elements and provide convenient methods like `Choice` and `Take` to easily select weighted random items.

They also behave just like standard collections: you can use `Add()`, `Remove()`, `Contains()`, `Clear()`, and `Count`, access elements directly via `[index]`, or read the underlying list using `Items`.

***

### <mark style="color:$success;">Types</mark>

* `WeightedList<T>` – Each element has an explicit numeric weight (`float`). Items with higher weights have a proportionally higher chance of being selected.
* `CurveWeightedList<T>` – Uses an `AnimationCurve` to determine selection weights based on the index or position of items, making it ideal for curve-driven drop rates and progression systems.

***

### <mark style="color:$success;">Methods</mark>

* `Choice()` - Selects a random element using the specified weights.
* `Take(int count)` - Returns random elements selected without replacement.

***

{% code title="Example.cs" %}

```csharp
[SerializeField] private WeightedList<int> myWeightedList;
[SerializeField] private CurveWeightedList<string> myCurveList;

private void Start()
{
    // Get random list element from WeightedList
    int value = myWeightedList.Choice();

    // Get random 2 list elements from WeightedList without replacement
    List<int> values = myWeightedList.Take(2);

    // Get random element using AnimationCurve weights
    string reward = myCurveList.Choice();
}
```

{% endcode %}
