util/rand: replace all non crypto rand stuff with own rand package
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package random
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/unistack-org/micro/v3/selector"
|
||||
"github.com/unistack-org/micro/v3/util/rand"
|
||||
)
|
||||
|
||||
type random struct{}
|
||||
@@ -20,10 +19,9 @@ func (r *random) Select(routes []string, opts ...selector.SelectOption) (selecto
|
||||
if len(routes) == 1 {
|
||||
return routes[0]
|
||||
}
|
||||
|
||||
var rng rand.Rand
|
||||
// select a random route from the slice
|
||||
//nolint:gosec
|
||||
return routes[rand.Intn(len(routes))]
|
||||
return routes[rng.Intn(len(routes))]
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package roundrobin
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/unistack-org/micro/v3/selector"
|
||||
"github.com/unistack-org/micro/v3/util/rand"
|
||||
)
|
||||
|
||||
// NewSelector returns an initialised round robin selector
|
||||
@@ -18,8 +17,8 @@ func (r *roundrobin) Select(routes []string, opts ...selector.SelectOption) (sel
|
||||
if len(routes) == 0 {
|
||||
return nil, selector.ErrNoneAvailable
|
||||
}
|
||||
|
||||
i := rand.Intn(len(routes))
|
||||
var rng rand.Rand
|
||||
i := rng.Intn(len(routes))
|
||||
|
||||
return func() string {
|
||||
route := routes[i%len(routes)]
|
||||
|
||||
Reference in New Issue
Block a user