How to make a random time from 2 to 8 seconds the script?

Good day!

Have code that changes the slides every 2 seconds. Tell me, please, how to make a random time between shifts slides from 2 to 8 seconds?

(function($) {
 $.fn.fader = function(options) {
 var settings = $.extend({
 delay: 2000
 }, options ); 

 $(this).addClass("clearfix").css("overflow", "hidden");
 $(this).find('ul').addClass("clearfix").css("padding", "0px");

/**
 * Fades out element `toFade`, fading in `toFade+1`
 * If `toFade` is the last element, then the first element will be
 * faded in.
*
 * @param {Integer} toFade which element to fade out
 * @param {Array} imgs array of jQuery elements
*/
 function fade(toFade, imgs) {
 imgs[toFade].animate({opacity: 0}, settings.delay/2);
 var toShow = toFade === (imgs.length - 1) ? 0 : toFade+1;
 imgs[toShow].animate({opacity: 1}, settings.delay/2);
 setTimeout(function() { 
 fade(toShow, imgs);
 }, settings.delay);
}

 // find images and hide them
 var imgs = [];
 $(this).find('ul li').each(function(){
imgs.push($(this));
 $(this).css({opacity: 0});
});

 // show the first image, and set a timer to fade it
 imgs[0].css({opacity: 1});
setTimeout(function(){
 fade(0, imgs);
 }, options.delay/2);
};

}(jQuery));
July 4th 19 at 23:35
2 answers
July 4th 19 at 23:37
Solution
1) Add the script function rand:
function rand(min, max){
 return Math.floor(Math.random() * (max - min + 1)) + min;
}

2) In line 4 replace delay: 2000 for delay: rand(2000, 8000)
July 4th 19 at 23:39
The line 24 settings.delay changed to Math.random()*6+2
If you want to display the first treated the new rule, and 38 change - shawn57 commented on July 4th 19 at 23:42
in Septe specially added block setting with the ability to change the delay time. Why deep to climb? - kiley_Gottli commented on July 4th 19 at 23:45

Find more questions by tags JavaScript