Skip to content

Instantly share code, notes, and snippets.

@juanbrujo
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanbrujo/972ed5d1dd488605fe90 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment