Show random number by setinterval

Hi,

I’m using a setInterval () block that pushes data via osc.
In this data there’s a message that should show a random number from 1 - 8.

I used this as random generator.

const soundtrigger = [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8];
const randSoundtrigger = soundtrigger[Math.floor(Math.random() * soundtrigger.length)];

This is the setInterval() block where the code pushes the data thru os to a device. I want to have the number changed every time the data sends.
I’ve tried to make a function out of the randSoundtrigger and put that after the value. But I just get the functionname in the osc post and I need the random number between 1 - 8.

setInterval(function() {
    var msg = {
        address: "/play/note",
        args: [
            {
                    // midi note value 
                        type: "i",
                        value: randSoundtrigger
            },
            {   // amp value a float to send decimal numbers
                type: "f",
                value: 1.5
            },
                {   // sustain value
                        type: "f",
                        value: 2
                    }
        ]
    };

    console.log("Sending message", msg.address, msg.args, "to", udpPort.options.remoteAddress + ":" + udpPort.options.remotePort);
    udpPort.send(msg);
}, timer);   =>>>>>> This timer value should be the result of post.length / 540 

A post was merged into an existing topic: Dividing post.length