开发者

Javascript - generate value from time (ms)

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 gene开发者_StackOverflow社区rate 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?


This should do the trick:

new Date().getTime()


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜