There are four methods of abcd. Each of these methods is executed for five seconds, and the sequence of the loop is random. How to realize it?

if I have four methods of abcd. Each of these methods is executed for five seconds, and the sequence is random. Is there a way to do this?

Mar.28,2021

what does random order mean? a sequence is provided here. Please refer to

.
function loop(fn){
    t = 5*1000
    var date = new Date()
    while(Date.now() - date < t){
        fn && fn()
    }
}
[a,b,c,d].forEach(loop)

let queue = [a, b, c, d]
setInterval(() => {
  queue[Math.floor(Math.random() * queue.length)]()
}, 5000)

do you mean to keep performing one of the arecalogical brecinct crecinct d for 5 seconds, and then randomly change another one for the next 5 seconds, and then cycle around non-stop?
this generally controls some display effects, which requires that a _ r _ c _ d and so on can be interrupted at will, and can be entered again.

fns=[a,b,c,d];
t=5*1000;
while(true){
    var datein=Date().now();
    fn=fns[ Math.floor(Math.random()*4) ];
    while(Date.now()-datein < t){
        (fn)();
    }    
}

need to modify abcd:

if the subject says that each method executes for 5 seconds, then I will assume that

  

Yes, just give a callback at random!

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eaa856-47dc4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eaa856-47dc4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?