2020-12-23 08:56:49 +00:00
|
|
|
package auditor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/rand"
|
|
|
|
)
|
|
|
|
|
|
|
|
// returns random uint64 number [0; n) outside exclude map.
|
|
|
|
// exclude must contain no more than n-1 elements [0; n)
|
|
|
|
func nextRandUint64(n uint64, exclude map[uint64]struct{}) uint64 {
|
|
|
|
ln := uint64(len(exclude))
|
|
|
|
|
|
|
|
ind := randUint64(n - ln)
|
|
|
|
|
2021-04-30 04:40:53 +00:00
|
|
|
for i := ind; ; i++ {
|
|
|
|
if _, ok := exclude[i]; !ok {
|
|
|
|
return i
|
2020-12-23 08:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns random uint64 number [0, n).
|
|
|
|
func randUint64(n uint64) uint64 {
|
|
|
|
return rand.Uint64(rand.New(), int64(n))
|
|
|
|
}
|