开发者

Javascript - generate value from time (ms)

开发者 https://www.devze.com 2023-02-24 17:15 出处:网络
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 nobod

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

精彩评论

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