Breaking Change: Random With Units

The random() function will no longer ignore units on the $limit argument in a future version. Passing a $limit with units is deprecated to ensure the compilation results don't change once the new behavior lands.

The random() function has historically ignored units in $limit and returned a unitless value. For example random(100px) would drop “px” and return a value like 42.

A future implementation of Dart Sass will stop ignoring units for the $limit argument and return a random integer with the same units.

SCSS Syntax

// Future Sass, doesn't work yet!
@debug math.random(100px); // 42px

Sass Syntax

// Future Sass, doesn't work yet!
@debug math.random(100px)  // 42px

Transition Period permalinkTransition Period

Compatibility:
Dart Sass
since 1.54.5
LibSass
Ruby Sass

First, the Sass compiler will emit a deprecation warning for previous uses of random() when the $limit argument has units. The warning will suggest a way to preserve the existing behavior and another way that emulates the future implementation.

In Dart 2.0.0 passing a $limit number with units will be an error, and then in a future minor release the random() function will return a random integer the same units as $limit.