I've been working on creating a scheduler function that can randomly call another function with parameters. Here's the JavaScript code I have so far:
function scheduleFunction(t, deltaT, functionName) {
var timeout;
var timeoutID;
function scheduler() {
functionName()
clearTimeout(timeoutID);
timeout = Math.trunc(Math.random() * 2 * deltaT - deltaT) + t;
timeoutID = setTimeout(scheduler, timeout);
}
scheduler();
}
The function works perfectly when calling functions without parameters. For example:
function printSomething() {
console.log("Printing something...");
}
scheduleFunction(1000, 500, printSomething);
However, it doesn't support calling functions with parameters. An example of what I'm trying to achieve is:
function print(string) {
console.log(string);
}
scheduleFunction(1000, 500, print("Hello World!"));
Is there a way to modify the scheduler function to allow for this type of functionality?