Skip to content

[Feature Request] Add 'rand' to Math Functions #2856

@luxlogica

Description

@luxlogica

It would be incredibly useful to be able to generate a random number - specially during development and testing, such as when we want to:

  • automatically generate a random colour
@randColor: rgb(rand(255),rand(255),rand(255));

.panel {
    background-color: @randColor;
    color: contrast(@randColor);
}
  • pick randomly from a selection of pre-defined styles:
@randStyle: rand(2);

.my-element1 {
    .testStyle(@randStyle);
}

.testStyle(@which) when (@which = 0) {
   // style definitions #1
}
.testStyle(@which) when (@which = 1) {
    // style definitions #2
}
.testStyle(@which) when (@which = 2) {
    // style definitions #3
}
  • access online API urls - such as Unsplash.it - with random parameters
@randImg: rand(1050);

.hero-banner {
    background-image: url("http://unsplash.it/500/300?image=@{randImg}");
}

The Math Functions provided by LESS are already pretty extensive, and the addition of a 'random' function to the core would make it pretty close to complete!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions