@function __shuffle($collection) {
  $collection: __to-iterable($collection);
  $index: 1;
  $length: length($collection);
  $result: ();

  @while ($index <= $length) {
    $rand: __base-rand(1, $index);

    @if ($index != $rand) {
      $result: __set($result, $index, __get($result, $rand));
    }

    $result: __set($result, $rand, __get($collection, $index));
    $index: $index + 1;
  }

  @return __to-list($result);
}

/// Creates a list of shuffled values, using a version of the Fisher-Yates
/// shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle)
/// for more details.
///
///
/// @access public
/// @group Collection
/// @param {List|Map|string} $collection The collection to shuffle.
/// @returns {List} Returns the new shuffled list.
/// @example scss
/// $foo: _shuffle((1, 2, 3, 4));
/// // => (4, 1, 3, 2)

@function _shuffle($args...) {
  @return call(get-function("__shuffle"), $args...);
}
