wiki:olivine/dsl/types/weighted

Weighting Entries in a List for Random Selection

Sometimes it is desirable to specify a list of things and have Olivine choose one of them from the list randomly. You might want to give a higher priority for random selection to some items in the list rather than an even distribution. This is where weighting comes into play. First off, this type is context-specific, that is it can only be used in certain contexts such as on an entry of a list. The general syntax for weighting a thing is thing @ value% where thing something (or anything really, it depends on what you're doing with it) and value is an integer that makes up a percentage weighting.

Every entry in a weighted list must have weighting values that add-up to 100% or less than 100% provided the remaining entries have no weighting, they will implicitly take-up the remainder adding-up to 100% split evenly.

Examples

Specify three items, one with 20% chance and another with 70% chance and the last one with 10% chance:

[
   &boat @ 20%
   &carrot @ 70%
   &bottle @ 10%
]

Specify two items, one with 15% chance and the other with 85% chance (the 85% is implied):

[
   &potato @ 15%
   &rotten_flesh
]

Specify three items, one with 50% chance, another with 10% chance and a third with 17% chance:

[
   &apple_pie @ 17%
   &red_brick
   &mmm:alpha_stew @ 50%
]

Two examples, both accomplish the same thing: four items, each with 25% chance:

[
   &foo
   &bar
   &gong
   &whiz
]
[
   &foo
   &bar @ 25%
   &gong
   &whiz
]

Four items, one with 15% chance, another with 5%, and two with 40% chance each:

[
   &hat @ 15%
   &car
   &stick @ 5%
   &apple
]
Last modified 4 years ago Last modified on May 22, 2020 12:00:47 AM