由买买提看人间百态

topics

全部话题 - 话题: genanyprob
(共0页)
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) {
... 阅读全帖
(共0页)