Javascript 如何使用Math.random()生成一个只有十分之一位的数字?

Javascript 如何使用Math.random()生成一个只有十分之一位的数字?,javascript,Javascript,class AlienShip{ 构造函数(){ //3到6之间的随机数 this.hull=Math.floor(Math.random()*4)+3; //介于2和4之间的随机数 this.firefower=Math.floor(Math.random()*3)+2; //介于.6和.8之间的随机数 this.accurity=Math.floor(Math.random()*1.2)+.6; } }您可以取一个系数和一个调整值,最后除以10 console.log(Math.floor

class AlienShip{
构造函数(){
//3到6之间的随机数
this.hull=Math.floor(Math.random()*4)+3;
//介于2和4之间的随机数
this.firefower=Math.floor(Math.random()*3)+2;
//介于.6和.8之间的随机数
this.accurity=Math.floor(Math.random()*1.2)+.6;
}

}
您可以取一个系数和一个调整值,最后除以10


console.log(Math.floor(Math.random()*3+6)/10)


(Math.random()*(max-min+1))+min

(数学随机()*(8-6+1)+6)/10

0.6到0.9

0.67.., 0.83.. 但绝对不能超过0.9




这将使最小值被包括,最大值被排除

(Math.random()*(max-min))+min

(数学随机()*(8-6)+6)/10


0.67..0.79。。但决不能超过0.8…

获取一个介于6和8之间的随机整数,然后将其除以10。请参阅此mdn文档()