Using Math.random() Method
Math.random() method generates a random number between 0 and 1. We can use this method to generate a random number based on the current date by multiplying the output of
Math.random() by the current date and then converting the result to an integer using the
let currentDate = new Date(); let randomNum = Math.floor(Math.random() * currentDate); console.log(randomNum);
Using Date.now() Method
Date.now() method returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. We can use this method to generate a random number based on the current date by taking the modulus of the output of
Date.now() with a large number and then adding 1 to avoid getting a value of 0.
let randomNum = (Date.now() % 100000) + 1; console.log(randomNum);
Both of these methods will generate a random number based on the current date. However, it's important to note that neither of these methods guarantee true randomness and should not be used for security purposes.