How to use setInterval with random number of milliseconds each time?
By : Gabriel Morais
Date : March 29 2020, 07:55 AM
wish of those help Felix said it: If you want to change the interval every time, use setTimeout instead. Simplified example as I'm having trouble following exactly what you want your original code to do: code :
doTheRandom();
function doTheRandom() {
random = randomizator(60000,200000);
// Up to 1 second
setTimeout(doTheRandom, randomizator(1000, 2000)); // 12 seconds
}

why give a random number when log in setInterval
By : Salomon Bronstein
Date : March 29 2020, 07:55 AM
around this issue Because setInterval() returns a unique number. And not a random number. This number is used in the function clearInterval()

setInterval + Random Number
By : Hector Moratilla
Date : March 29 2020, 07:55 AM
To fix the issue you can do The x variable is defined in the myInterval function, so is inaccessible inside ref()  hence the error. You need to raise it's scope: code :
var x = 0;
function myInterval() {
x = Math.round(Math.random() * 5000) + 1;
}
var timeoutId = setTimeout(ref, 100);
var intervalId = setInterval(ref, 5000);
var intervalId = setInterval(myInterval, 5000);
// ANIMATED NUMBER
function ref() {
$("#budgetleft").animateNumbers(x);
}
var intervalId = setInterval(function() {
var randomNumber = Math.round(Math.random() * 5000) + 1;
$("#budgetleft").animateNumbers(randomNumber);
}, 5000);

How to find previous randomly generated number using Math.random in a setInterval function?
By : Yuan Luo
Date : March 29 2020, 07:55 AM
I hope this helps . You could take a closure over the last random value and check against it. code :
function showRandomDotIcon() {
var last;
return function () {
var randomDot;
do {
randomDot = Math.floor(Math.random() * 13) + 1;
} while (last === randomDot)
last = randomDot;
console.log(randomDot);
};
}
setInterval(showRandomDotIcon(), 1000);

[HelpSQL]: i don't want the same number in cell when i am updating table column next time using Random function
By : Mehmet Yılmaz
Date : March 29 2020, 07:55 AM
this one helps. Your question is pretty ambiguous, but I don't have enough reputation to get you to clarify it... So I am interpreting what you want is to set the SetID to a number between 1 and 5 and you don't want to use the same number as the row had before the UPDATE. If that's the case, then this is my answer: code :
update E SET SetID = case when SetID <> r1.R1To5 then r1.R1To5
when SetID <> r2.R1To5 then r2.R1To5
when SetID <> r3.R1To5 then r3.R1To5
when SetID <> r4.R1To5 then r4.R1To5
when SetID <> r5.R1To5 then r5.R1To5
else case when SetID = 5 then 1
else SetID +1
end
end
from Employee E
cross apply (VALUES (CAST(RAND(CHECKSUM(NEWID())) * 5 as INT) + 1 )) r1 (R1To5)
cross apply (VALUES (CAST(RAND(CHECKSUM(NEWID())) * 5 as INT) + 1 )) r2 (R1To5)
cross apply (VALUES (CAST(RAND(CHECKSUM(NEWID())) * 5 as INT) + 1 )) r3 (R1To5)
cross apply (VALUES (CAST(RAND(CHECKSUM(NEWID())) * 5 as INT) + 1 )) r4 (R1To5)
cross apply (VALUES (CAST(RAND(CHECKSUM(NEWID())) * 5 as INT) + 1 )) r5 (R1To5)
GO

