Function

@p, @P

Pick one of the arguments at random. @P does the same but never returns the value it picked last time at the same place.

Syntax

  • @p(<value>, ...)
  • @p([<range>])
  • @p(--<variable>)
  • @p()
  • @P(<value>, ...)
value
Anything, including other function calls. Wrap a value in quotes or parentheses if it contains a comma.
range
Characters in brackets, expanded to a list: [a-z], [0-9a-f], [A-Z0-9].
--variable
A custom property. Its value is read at generation time, and a comma-separated value becomes several candidates.

@p() with no arguments picks again from the arguments of the previous @p. Compose with @cycle or @mirror as @p.cycle(…). The last picked value is available as @lp. The sequence of picks depends on the seed. @pick is an older name.

Examples

@grid: 5 / 60vmin _1px;
background: @p(#000, #e6437d, #ebbf4d);
@grid: 5 / 60vmin _1px;
background: #000;
color: #fff;
@content: @p([A-Z]);

Picking from a list stored in a variable:

@grid: 6 / 60vmin _1px;
--colors: #cc063e, #fd9407, #e2d9c2, #10898b;
background: @p(--colors);
@shape: @p(circle, hexagon);

@P avoids repeating the previous pick, which keeps neighbouring cells different in a one-dimensional grid:

@grid: 1x12 / 60vmin;
background: @P(#000, #e6437d, #ebbf4d);

See also