Math.random()
生成0-1之間的隨機(jī)數(shù)沙庐,包括0,不包括1
寫一個(gè)函數(shù)返回從min到max之間的 隨機(jī)整數(shù)佳吞,包括min包括max
function getRandom(min,max){
var random=Math.floor(Math.random()*(max-min+1)+min);
return random
}
生成隨機(jī)IP地址
function getRandomIp(){
var ip='';
for(var i=0;i<4;i++){
ip+=Math.floor(Math.random()*256)+'.'
}
return ip.slice(0,ip.length-1)
}
生成隨機(jī)顏色
function getRandomColor(){
var str='0123456789abcdef';
var color='#';
for(var i=0;i<6;i++){
color+=str[Math.floor(Math.random()*str.length)]
}
return color
}