Function

@r, @ri

A random number in a range, evaluated separately for every cell. @ri gives a whole number.

Syntax

  • @r, @r(<max>), @r(<min>, <max>)
  • @r(<from>, <to>) with letters
  • @ri, @ri(<max>), @ri(<min>, <max>)
  • @r(<key>: <min>, <max>), @ri(<key>: <min>, <max>)
min, max
The bounds, with an optional unit that is carried to the result. @r includes the lower bound and excludes the upper. @ri returns every whole number from one bound to the other, each as likely. Without arguments the range is 0 to 1. With one argument it is 0 to that value. @r(±10) is @r(-10, 10).
from, to
Two letters: a random letter from the first to the second, both included.
key
An expression. The same key gives the same number.

The sequence of random values depends on the seed. The last value can be reused with @lr. @rand and @random are other names of @r.

Examples

Click a preview for a new variation. The values are chosen when the doodle is generated, not over time.

A new length, angle and opacity for every cell:

@grid: 12 / 60vmin;
@size: @r(40%, 100%) 2px;
margin: auto;
background: #000;
opacity: @r(.25, 1);
rotate: @r(180deg);

@ri(1, 6) casts a die:

@grid: 6 / 60vmin _1px;
background: #000;
color: #fff;
@content: @ri(1, 6);
font: 700 1.4em / 1 monospace;

Two letters give a random letter from one to the other:

@grid: 8 / 60vmin;
@content: @r(a, z);
font: 700 @ri(12, 28)px / 1 monospace;
color: #000;
opacity: @r(.25, 1);

The ± shorthand is a symmetric range: @r(±25deg) means @r(-25deg, 25deg).

@grid: 8 / 60vmin;
@size: 70%;
margin: auto;
border: 1px solid #000;
translate: @r(±20%) @r(±20%);
rotate: @r(±25deg);

Keys

Each @r is a new draw, so two of them in one cell give two numbers. With a key before a colon, @r(k: a, b) gives the number that key draws, and the same key gives it again. Here each cell slopes from its own height, @r(@i: …), to the next cell's, @r(@i + 1: …):

@grid: 24x1 / 60vmin;
background: #000;
clip-path: polygon(
  0 100%, 0 @r(@i: 20%, 80%),
  100% @r(@i + 1: 20%, 80%), 100% 100%
);

See also