randomNextIntNotZero static method
随机一个不为零的整数
参数
- max 随机数范围,最大值。即
1-max
中随机 - condition 其他满足条件
Implementation
static int randomNextIntNotZero(int max, [bool condition = true]) {
var ran = Random();
int _remain = ran.nextInt(max);
bool stop = (_remain == 0);
while (stop) {
_remain = ran.nextInt(max);
stop = !(_remain != 0 && condition);
}
return _remain;
}