随机数

  作者:chrispy

//时间戳随机数var d = new Date()var vYear = d.getFullYear()var vMon = d.getMonth() + 1var vDay = d.getDate()var h = d.getHours();var m = d.getMinutes();var se = d.getSeconds();var s = vYear+(vMon<10 ? "0" + vMon : vMon)+(vDay<10 ?

//时间戳随机数

var d = new Date()

var vYear = d.getFullYear()

var vMon = d.getMonth() + 1

var vDay = d.getDate()

var h = d.getHours(); 

var m = d.getMinutes(); 

var se = d.getSeconds(); 

var s = vYear+(vMon<10 ? "0" + vMon : vMon)+(vDay<10 ? "0"+ vDay : vDay)+(h<10 ? "0"+ h : h)+(m<10 ? "0" + m : m)+(se<10 ? "0" +se : se);

console.log(s);



//生成4位随机数

var charactors="0123456789";

var value='';

for(j=1;j<=4;j++){

    var i = parseInt(10*Math.random());

    value += charactors.charAt(i);

}

console.log(value);


有用  |  无用

猜你喜欢