-2

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?

  • 1
    you tried what so far? – messerbill Feb 06 '18 at 11:21
  • You are probably looking for seeding. It is explained here https://stackoverflow.com/questions/424292/seedable-javascript-random-number-generator – Ngob Feb 06 '18 at 11:24
  • 1
    Possible duplicate of [Generating random whole numbers in JavaScript in a specific range?](https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range) – tinamou Feb 06 '18 at 11:42

1 Answers1

0
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));
Shiva Kishore
  • 1,611
  • 12
  • 29