at-import / SassyLists

MIT License
276 stars 27 forks source link

fixes random function #54

Closed mknadler closed 8 years ago

mknadler commented 8 years ago

As mentioned (albeit briefly) in #50, the random function is currently broken :sob:

Previously, @function sl-random-value looked like this:

@return nth($list, random(length($list) - 1) + 1);

Because this function works by adding 1 to the random number generated between 1 and a maximum value, the lowest possible return for this function is 2.

In addition, the above version will loudly fail if a list has only one item.

So: in it's current form, the function returns a random list item between the 2nd and last, but only if the list has at least two items.

The subtraction and addition seem to be unnecessary; a straight random(length($list))) works just fine, and hits all potential numbers in the list.

The version included in this PR makes it so that the function simply returns a random list item:

@return nth($list, random(length($list)));
KittyGiraudel commented 8 years ago

Very nice Miri. :)