0

I need to generate some values on Javascript, by clicking on a button, that can't be the same of previous values. I think to generate it from time in ms (in fact I think nobody can't click a button faster than a ms, right?).

What do you think? And how can I do this?

markzzz
  • 47,390
  • 120
  • 299
  • 507

2 Answers2

3

This should do the trick:

new Date().getTime()
Felipe
  • 1,290
  • 10
  • 11
2

yes, I think its pretty solid to use complete datetime (including milliseconds) as a seed for generating a random number.

var currentTime = new Date(),
    time = currentTime.getTime();

Check out related question: Seedable JavaScript random number generator

Also, see David Bau's blog for more information on seeding: http://davidbau.com/archives/2010/01/30/random_seeds_coded_hints_and_quintillions.html#more

Community
  • 1
  • 1
Scherbius.com
  • 3,396
  • 4
  • 24
  • 44