Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Last active July 29, 2025 03:56
Show Gist options
  • Select an option

  • Save juanbrujo/972ed5d1dd488605fe90 to your computer and use it in GitHub Desktop.

Select an option

Save juanbrujo/972ed5d1dd488605fe90 to your computer and use it in GitHub Desktop.
LESS mixin to get random from array
@blue: #009be1;
@green: #64c200;
@red: #ff1842;
@orange: #ffbf00;
@yellow: #ffd400;
@colors: '@{green}','@{blue}','@{red}','@{orange}','@{yellow}';
.randomFromArray(@min: 1, @max: length(@colors), @int: 0) {
@getNum: `Math.random() * (@{max} - @{min} + @{int})`;
@base: unit(`@{int} == 1 ? Math.floor(@{getNum}) : @{getNum}`);
@randNum: floor( @base + @min );
@color: e( extract(@colors, @randNum) );
}
// USE
body {
.randomFromArray();
background-color: @color;
}
@jamescopelands
Copy link
Copy Markdown

@geometry dash meltdown I can't find any errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment