@r, @ri
A random number in a range, evaluated separately for every cell.
@ri keeps the integer part of that number.
Syntax
- @r, @r(<max>), @r(<min>, <max>)
- @r(<from>, <to>) with letters
- @ri, @ri(<max>), @ri(<min>, <max>)
- min, max
-
The bounds, with an optional unit that is carried to the result.
The range includes the lower bound and excludes the upper, so
@ri(1, 5)is1,2,3or4. 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 between them, such as
@r(a, z).
The sequence of random values depends on the seed.
The last value can be reused with @lr.
@rand is an older name 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, 7) is 1–6: the integer part of a number in that range, not a rounded value.
@grid: 6 / 60vmin _1px;
background: #000;
color: #fff;
@content: @ri(1, 7);
font: 700 1.4em / 1 monospace; Two letters give a random letter between them. Integer font sizes keep the type on a whole pixel.
@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);