Is there any way I can generate a random number from 1 to 4 based on the current month.
So in a month it will return the same value, a different value the next month and a different one the coming month and so on?
Is there any way I can generate a random number from 1 to 4 based on the current month.
So in a month it will return the same value, a different value the next month and a different one the coming month and so on?
function random(seed) {
var x = Math.sin(seed++) * 10000;
return x - Math.floor(x);
}
var d = new Date();
rand = random(d.getMonth());
console.log(rand*4);
if you want integers
console.log(Math.floor(rand*4));