一个函数,有一定概率返回true
函数f(int x),有x%概率返回true,这两种方法哪个更好?
//1
bool f(int x)
{
return rand() % 100 < x;
}
//2
bool f(int x)
{
return (float)rand() / (float) RAND_MAX < (float)x / (float)100;
}
...全文


