---
name: "selectRandomWeighted"
type: command
status: ok
groups: ["Arrays"]
arma3_since: "1.76"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/selectRandomWeighted
revid: 377677
updated: 2026-01-02T09:02:40Z
---

# selectRandomWeighted

*Command · Arrays · Arma 3 v1.76*

## Description

Returns a random element from the given array according to assigned weights. Engine solution to [BIS_fnc_selectRandomWeighted](../functions/BIS_fnc_selectRandomWeighted.md). A few notes:
- Negative weights are not supported
- If an item's weight is 0, the item is ignored
- The weights don't have to total to 1
- If numbers of items and weights do not match, the shortest array is used
- A single array Syntax is slightly faster than Alt Syntax

## Syntax

### Syntax 1

```sqf
selectRandomWeighted valuesAndWeights
```

**Parameters:**

- `valuesAndWeights`: [Array](../topics/Array.md) with [valueN, weightN]
  - valueN: [Anything](../topics/Anything.md) - weighted value
  - weightN: [Number](../topics/Number.md) - values relative weight

**Returns:** [Anything](../topics/Anything.md) - random weighted value or [Nothing](../topics/Nothing.md) if array is empty or all weights are 0

### Syntax 2

```sqf
values selectRandomWeighted weights
```

**Parameters:**

- `values`: [Array](../topics/Array.md) of [Anything](../topics/Anything.md)
- `weights`: [Array](../topics/Array.md) of [Number](../topics/Number.md)s

**Returns:** [Anything](../topics/Anything.md) - random weighted value or [Nothing](../topics/Nothing.md) if any of arrays is empty or all weights are 0

## Examples

### Example 1

```sqf
private _randomWeightedElement = selectRandomWeighted [1,0.1,2,0.2,3,1.3,4,2.4,5,7.5];
```

### Example 2

```sqf
private _randomWeightedElement = [1,2,3,4,5] selectRandomWeighted [0.1,0.2,1.3,2.4,7.5];
```

## See also

[random](../commands/random.md) · [select](../commands/select.md) · [selectRandom](../commands/selectRandom.md) · [selectMin](../commands/selectMin.md) · [selectMax](../commands/selectMax.md)

## Community notes

**Killzone_Kid** — 2017-06-26

A 100000 runs of the following code:

```sqf
_values = [0,1,2,3,4,5,6,7,8,9];
_weights = [0.109,0.65,0.01,1.01,1.24,0,1.59,0.09,1.15,0.55];
_result = _values selectRandomWeighted _weights;
```

Gave this result:

```
0 - 0
0.01 - 144
0.09 - 1409
0.109 - 1633
0.55 - 8673
0.65 - 10127
1.01 - 15668
1.15 - 18059
1.24 - 19518
1.59 - 24769
```

<sub>Source: [BI Community Wiki — selectRandomWeighted](https://community.bistudio.com/wiki/selectRandomWeighted) (revision 377677).</sub>
