Changes between Initial Version and Version 1 of olivine/dsl/types/weighted


Ignore:
Timestamp:
May 22, 2020 12:00:47 AM (4 years ago)
Author:
jonathan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • olivine/dsl/types/weighted

    v1 v1  
     1= Weighting Entries in a List for Random Selection =
     2Sometimes 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'' some''thing'' (or any''thing'' really, it depends on what you're doing with it) and ''value'' is an `integer` that makes up a percentage weighting. 
     3
     4Every 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.
     5
     6== Examples ==
     7Specify three items, one with 20% chance and another with 70% chance and the last one with 10% chance:
     8{{{
     9[
     10   &boat @ 20%
     11   &carrot @ 70%
     12   &bottle @ 10%
     13]
     14}}}
     15
     16Specify two items, one with 15% chance and the other with 85% chance (the 85% is implied):
     17{{{
     18[
     19   &potato @ 15%
     20   &rotten_flesh
     21]
     22}}}
     23
     24Specify three items, one with 50% chance, another with 10% chance and a third with 17% chance:
     25{{{
     26[
     27   &apple_pie @ 17%
     28   &red_brick
     29   &mmm:alpha_stew @ 50%
     30]
     31}}}
     32
     33Two examples, both accomplish the same thing: four items, each with 25% chance:
     34{{{
     35[
     36   &foo
     37   &bar
     38   &gong
     39   &whiz
     40]
     41}}}
     42{{{
     43[
     44   &foo
     45   &bar @ 25%
     46   &gong
     47   &whiz
     48]
     49}}}
     50
     51Four items, one with 15% chance, another with 5%, and two with 40% chance each:
     52{{{
     53[
     54   &hat @ 15%
     55   &car
     56   &stick @ 5%
     57   &apple
     58]
     59}}}