Non sequential order when running slideshow

I used this code to let my slideshow start with a random image within the slides;

$w.onReady( function () {
let rnd = Math.floor(Math.random() * 7);
$w(“#slideshow1”).changeSlide(rnd)
.then( (newSlide) => {
$w(‘#slideshow1’).show()
} );
});

It works fine except the next image is not random but rather sequential ( the next slide in the list) I am a novice where coding is concerned and was wondering what help can be offered to allow this random function in the slideshow. thanks in advance

Wrap it under a setInterval() function

$w.onReady(function () {
   setInterval( () => {
      let rnd = Math.floor(Math.random() * 7) + 1
      $w("#slideshow1").changeSlide(rnd);
   }, 3000); //3000 milliseconds a.k.a. 3 seconds
});

& disable auto slide

Thanks much it works with the exception of the first slide is not random i tried playin with the code to get it to work to no avail. I set the images to crossfade is there any way to get the first image to crossfade also? thats not happening either. thank much

@taqtech Have you disabled the auto slide from the Slideshow’s settings?

hey yea i disabled it but its still doin the same thing. The original code that i posted randoms the first slide… im tryna figure it out but im no code master. i copied n pasted wat u sent, no dice, tried messing with what you sent as well as what i posted to get it working but im stumped…

Use this:
$w.onReady(function () {
let numberOfSlides = 3; //must equal number of slides in slideshow
let currentSlide = Math.floor(Math.random() * numberOfSlides); //generate a random number between 0 and max
let intervalId = setInterval(changeSlide, 99999); //store the interval ID in a variable

function changeSlide(nextSlide) {
currentSlide = nextSlide; //update the current slide to the next slide index passed as an argument
$w(“#slideshow1”).changeSlide(currentSlide);
}

$w(“#button4”).onClick(() => { //add an event listener to the button element
let nextSlide = Math.floor(Math.random() * numberOfSlides); //generate a new random number for the next slide
while (nextSlide === currentSlide) { //check if the new random number is the same as the current slide
nextSlide = Math.floor(Math.random() * numberOfSlides); //if it is, generate a new random number
}
changeSlide(nextSlide); //call the changeSlide() function with the new random slide index
});

});