How can I generate a random number every 24 hours in JavaScript? -


i trying generate word of day list of words stored in database. how can generate random number every 24 hours can use id words database? thank you!

strange stuff in client-side javascript, here goes:

random number generator

// returns random integer between min , max // using math.round() give non-uniform distribution! function getrandom(min, max) {   return math.floor(math.random() * (max - min + 1) + min); } 

generate new number every 24 hours

var rand = getrandom();  var handle = setinterval(function () {     rand = getrandom(lower_bound, upper_bound);     // console.log("new random number is: " + rand); }, 1000 * 60 * 60 * 24); 

notes

  • see math.random() , math.floor()for details on generator.
  • see setinterval() details on setting timer, , clearinterval() if need cancel repeat event using handle variable.
  • set lower_bound , upper_bound based on needs (here, defined number of items in table).
  • adapt timer needed.
  • you may want consider stronger random number generator this, there plenty of more advanced (but more complex) alternatives.

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -