I think it's better to use only 1 variable, which will contain all values including their weights:

JavaScript:

```
$gameVariables.setValue(13, [
{ value: 10, weight: 0.2 },
{ value: 3, weight: 0.33 },
{ value: 50, weight: 0.1 },
{ value: 20, weight: 0.37 }
]);
```

This will store your data in variable #13.

From there, it's as simple as calculating

`value * weight / sum_of_all_weights`

. In this case, the

`sum_of_all_weights`

just happens to be 1 (100%), but let's use it anyway, so we can use arbitrary weights without having to calculate their percentage first.

JavaScript:

```
var data = $gameVariables.value(13);
var sumOfWeights = data.map(function(d) { return d.weight }).reduce(function(a, b) { return a + b; }, 0);
$gameVariables.setValue(14, data.map(function(d) { return d.value * d.weight / sumOfWeights; }));
```

This will store the weighted values from variable #13 into variable #14 (you could also store it back into variable #13 instead, if you want).

You can retrieve each data point like this:

JavaScript:

`$gameVariables.setValue(15, $gameVariables.value(14)[0]);`

This will store the first element from variable #14 into variable #15. In this case, the value is 2 (because

`10 * 20% = 2`

).

JavaScript:

`$gameVariables.setValue(16, $gameVariables.value(14)[1]);`

This will store the second element from variable #14 into variable #16. In this case, the value is 0.99 (because

`3 * 33% = 0.99`

).

And so on. Just remember that arrays (what we use to store multiple data into a single variable) are 0-based, so the first element has index 0, the second has index 1, etc. By contrast, RPG Maker variables and switches are 1-based, so the first variable/switch has index 1 instead.