There is no perfect solution to this problem, two options are possible here:
Simple and complex, which should be more accurate.
If you use the same time on all devices *, you can use new Date().getTime() % 30000 for the first call, so they are all synchronized, and then always use the 30000 constant in timeout.
function getRandomNumber(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } setTimeout(function() { getRandomNumber(0, 14); }, new Date().getTime() % 30000);
* Time intervals will not matter, but seconds are minutes
Another way would be to let the server pass its time, and then guess the delay to fix the load time, and use this instad new Date().getTime()
source share