我需要我的网页播放随机视频,但JS不断重复相同的随机视频,除非我刷新网页



HTML部分循环播放由JS选择的随机选择的相同视频。如果我刷新html,它会播放一个不同的视频。我希望它选择一个不同的随机视频后,每个延迟到期。我很抱歉,我对编程有点陌生,我的术语很差。

//HTML
{url:randvideo1, delayms:10000},
//video arrays found in JS
var videoArray1 = [
"v/video01.mp4",
"v/video02.mp4",
"v/video03.mp4",
"v/video04.mp4"
];
var randvideo1 = videoArray1[Math.floor(Math.random()*videoArray1.length)];

您可能正在寻找每给定时间调用一个函数的setInterval

const delay = 3000;
var videoArray1 = [
"v/video01.mp4",
"v/video02.mp4",
"v/video03.mp4",
"v/video04.mp4"
];
function playVideo() {
var randvideo1 = videoArray1[Math.floor(Math.random() * videoArray1.length)];

console.log(`Playing video ${randvideo1} for ${delay / 1000} seconds...`)

/* 
The rest of your code to set the new video source in the html.
*/
}
setInterval(playVideo, delay);