# `WeightedRandom.Backend`
[🔗](https://github.com/greetingsfellowhumans/weighted_random/blob/main/lib/weighted_random/backend/backend.ex#L1)

WeightedRandom.Backend offers a contract to all who implement it:
1. The main WeightedRandom package presents a novel interface for generating a list of probabilities (floats that can be summed to equal exactly 1.0).
2. The custom Backend module decides what to do with those probabilities once they are generated.

# `backend_opts`

```elixir
@type backend_opts() :: [{:probability_type, probability_type()}]
```

# `index`

```elixir
@type index() :: integer()
```

# `indices`

```elixir
@type indices() :: [index()]
```

# `opts`

```elixir
@type opts() :: keyword()
```

# `percentage`

```elixir
@type percentage() :: float()
```

# `probability_type`

```elixir
@type probability_type() :: :weights | :probabilities
```

# `t`

```elixir
@type t() :: %WeightedRandom.Backend{
  backend: atom(),
  outcomes: list(),
  table: struct()
}
```

# `table`

```elixir
@type table() :: struct()
```

# `weight`

```elixir
@type weight() :: WeightedRandom.Input.Weight.t()
```

# `weights`

```elixir
@type weights() :: [weight()]
```

# `options`
*optional* 

```elixir
@callback options() :: keyword()
```

Optionally provide the opts kwli 

# `preprocess`

```elixir
@callback preprocess(input :: WeightedRandom.Input.t(), opts :: opts()) :: table()
```

`weights` is a list of floats which, if summed, would equal exactly 1.0. Each float represents the probability of being selected in the random sample.

So if given `[0.25, 0.25, 0.5]`, then index 2 is twice as likely to be sampled as index 1.

This function must return some kind of struct that will later be passed into `take/2`.

# `take`

```elixir
@callback take(table :: struct(), count :: integer()) :: indices :: [index :: integer()]
```

Given the struct returned by `preprocess/2`, return a list of random indices equal to `count`.

# `list_probability_types`

# `preprocess`

# `take`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
