Link Search Menu Expand Document

Picking values

Table of contents

  1. Picking from value lists
  2. Picking unique values
  3. Picking using indices

Picking from value lists

Picking can be used to generate random values based on a set list of values.

/** Definining lists */
filterManager.install(
  closet.recipes.setList({ tagname: 'setl' }),
)

/** Picking and Evaluation */
filterManager.install(
  closet.recipes.pick({ tagname: 'pick' }),
  closet.recipes.pickIndex({ tagname: 'pi' }),
  closet.recipes.pickCardNumber({ tagname: 'sel' }),
)
My favorite fruit is [[pick::fruits[[setl::fruits::apple||banana||grapefruit]]]]
Your favorite fruit is [[pick::fruits]]
Her favorite fruit is [[pick::fruits]]
His favorite fruit is [[pick::fruits]]

Picking unique values

You can control the picking of values and restrict it to unique values, if you provide an index. Within the same picking index, the same value will never be picked twice.

In fact it will refuse to pick any further value, once it exhausted the values. So make sure, you don’t pick more values than there are within the list.

Notice that this makes it behave similiar to shuffling values.

/** Definining lists */
filterManager.install(
  closet.recipes.setList({ tagname: 'setl' }),
)

/** Picking and Evaluation */
filterManager.install(
  closet.recipes.pick({ tagname: 'pick' }),
  closet.recipes.pickIndex({ tagname: 'pi' }),
  closet.recipes.pickCardNumber({ tagname: 'sel' }),
)
Peter's favorite fruit is [[pick1::fruits[[setl::fruits::apple||banana||grapefruit]]]]
Paul's favorite fruit is [[pick1::fruits]]
Patty's favorite fruit is [[pick1::fruits]]

Susan's favorite fruit is [[pick2::fruits]]
Saul's favorite fruit is [[pick2::fruits]]
Sam's favorite fruit is [[pick2::fruits]]
Sandra's favorite fruit is [[pick2::fruits]]

Picking using indices

As an alternative to random picking, you can also pick with an index. The index is provided as the tag index. When picking this way, the same value can be caught multiple times without any issue.

/** Definining lists */
filterManager.install(
  closet.recipes.setList({ tagname: 'setl' }),
)

/** Picking and Evaluation */
filterManager.install(
  closet.recipes.pick({ tagname: 'pick' }),
  closet.recipes.pickIndex({ tagname: 'pi' }),
  closet.recipes.pickCardNumber({ tagname: 'sel' }),
)
Peter's favorite fruit is [[pi::fruits[[setl::fruits::apple||banana||grapefruit]]]].
Susan's favorite fruit is [[pi2::fruits]].
Daniel's favorite fruit is [[pi1::fruits]].
Alan's favorite fruit is [[pi1::fruits]], as well.

This is especially useful, if you want to specify a template, and only provide the different values.

/** Debug features */
filterManager.install(
  closet.recipes.debug(),
  closet.recipes.define({ tagname: 'def' }),
  closet.recipes.specification.hide({ tagname: 'spec' }),
)

/** Definining lists */
filterManager.install(
  closet.recipes.setList({ tagname: 'setl' }),
)

/** Picking and Evaluation */
filterManager.install(
  closet.recipes.pick({ tagname: 'pick' }),
  closet.recipes.pickIndex({ tagname: 'pi' }),
  closet.recipes.pickCardNumber({ tagname: 'sel' }),
)
<!--
[[spec1::[[setl::v::1||2||3]]]]
[[spec2::[[setl::v::3||5||8]]]]
[[spec3::[[setl::v::-2||8||6]]]]
-->[[pi::v]] + [[pi1::v]] = [[pi2::v]]