rosedb
rosedb copied to clipboard
fix the rare case of infinite loop
The function randomLevel has a very low probability to fall into an infinite loop. Besides, we can use rand.Float64() to generate a pseudo-random number between 0.0 and 1.0, instead of using rand.Int31() and the mask operation.
the current version of randomLevel is:
func randomLevel() int16 {
var level int16 = 1
for level < maxLevel {
if rand.Float64() < probability {
break
}
level++
}
return level
}