我想要创建一个函数,它在调用时大部分时间返回true,但它偶尔会返回false?
偶尔,我的意思是,在1000个呼叫时,平均每50个呼叫就有一个false。
发布于 2014-02-28 15:34:08
怎么样
赔率: 50/1000 = 1/20
//Get random number from 1 to 20, if equals 20 return false
if (Math.floor((Math.random()*20)+1) == 20)
{
return false;
}
else{
return true;
}https://stackoverflow.com/questions/22099275
复制相似问题