setTimeout 随机时间

setTimeout random time

您好,我怎样才能将它更改为 30-50 秒之间的随机时间? 我不需要新代码或其他东西只是想编辑这个


client.on('chat', function(channel, user, message, self) {
    if (user.username == 'Cortex' && message === 'sar') {
        
        test();
        
    }
});


function test() 
{
    setInterval(function() {
        var spamMessage = 'KEK ';
        var toSpam = 'MingLee';
        for (i = 0; i < 30; i++) {
            spamMessage += toSpam + ' '; 
        }
        client.say(channel, spamMessage)
    }, 30000);
} 

是这样的吗?

client.on('chat', function(channel, user, message, self) {
    if (user.username == 'Cortex' && message === 'sar') {
        
        test();
        
    }
});


function test() 
{
    const min = 30000;
    const max = 50000;

  const time =  Math.floor(Math.random() * (max - min)) + min;

    setInterval(function() {
        var spamMessage = 'KEK ';
        var toSpam = 'MingLee';
        for (i = 0; i < 30; i++) {
            spamMessage += toSpam + ' '; 
        }
        client.say(channel, spamMessage)
    }, time);
}