rosedb icon indicating copy to clipboard operation
rosedb copied to clipboard

fix the rare case of infinite loop

Open chentaiyue opened this issue 3 years ago • 1 comments

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.

chentaiyue avatar Aug 05 '22 08:08 chentaiyue

the current version of randomLevel is: func randomLevel() int16 { var level int16 = 1 for level < maxLevel { if rand.Float64() < probability { break } level++ } return level }

chentaiyue avatar Aug 09 '22 14:08 chentaiyue