s**********e 发帖数: 326 | 1 来自主题: JobHunting版 - 一个小题目 贴个我的代码:
evenProb have 50/50 probability to return true, genAnyProb can return true
with any prob(first parameter)
main should call genAnyProb like this: genAnyProb(0.6,1,0.00001)
public boolean evenProb() {
return new Random().nextInt(2) == 0;
}
public boolean genAnyProb(double prob, double base, double epsilon) {
if (prob * base < epsilon) {
return true;
}
if (prob == 0.5) {
return evenProb();
} else if (prob > 0.5) {
... 阅读全帖 |
|