Prefix may not be properly filled
kozlovic opened this issue · 0 comments
kozlovic commented
The RandomizePrefix
function seems to be incorrect. The loop is using l
as the condition to continue, however, there is no guarantee that l
is going to be big enough that the loop will cover all 12 indexes of the prefix array:
https://github.com/nats-io/nuid/blob/master/nuid.go#L111
Actually, since maxPre
(36^12) is used as the max for rand.Int(rand.Reader, big.NewInt(maxPre))
, it is quite probable. A quick test showed that 2% of runs, i
would end-up greater than 0
at the end of the loop. Should the condition had been i
? or should maxPre be the minimum acceptable value for r
, and therefore rand.Int()
should be passed the max int64
value?