---
name: "BIS_fnc_selectRandomWeighted"
type: function
status: ok
groups: ["Arrays"]
arma3_since: "0.50"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/BIS_fnc_selectRandomWeighted
revid: 327996
updated: 2022-07-13T15:41:47Z
---

# BIS_fnc_selectRandomWeighted

*Function · Arrays · Arma 3 v0.50 · introduced in Arma 2 v1.00*

## Description

Selects a random item from an array, taking into account item weight.

> [!NOTE]
> - The weights do not have to total to 1
> - The length of weights and items arrays may not match, in which case the shortest array is used for length

> [!NOTE]
> **Arma 3:** See [selectRandomWeighted](../commands/selectRandomWeighted.md) for an engine solution.

## Syntax

### Syntax 1

```sqf
itemsAndWeights call BIS_fnc_selectRandomWeighted
```

**Parameters:**

- `itemsAndWeights`: [Array](../topics/Array.md) - array of items and weights [item, weight, item, weight...]

**Returns:** [Anything](../topics/Anything.md)

### Syntax 2

```sqf
[items, weights] call BIS_fnc_selectRandomWeighted
```

**Parameters:**

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

**Returns:** [Anything](../topics/Anything.md)

## Examples

### Example 1

```sqf
["apples",.3,"pears",.2,"bananas",.4,"diamonds",.1,"unicorns",.00001] call BIS_fnc_selectRandomWeighted;
```

### Example 2

```sqf
[["apples","pears","bananas","diamonds"], [0.3,0.2,0.4,0.1]] call BIS_fnc_selectRandomWeighted;
```

## See also

[selectRandomWeighted](../commands/selectRandomWeighted.md)

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