The situation I am currently experiencing is that it only occur on my online app. I try it at local but I can not got the result.
haha... I make a mistake.
func WeightRandom(services []*registry.Service) Next{
w := weighted.NewRandW()
for _, service := range services {
for _,n := range service.Nodes {
w.Add(n,n.Weight)
}
}
return func() (*registry.Node, error) {
n := w.Next()
no, ok := n.(*registry.Node)
if !ok {
return nil,errors.New("get next err")
}
return no, nil
}
}
The 'rand.New(...SEED)' is outside the loop of for But I neglect that this func 'WeightRandom' will be mass goroutine call. so each time.Now().Unix() ,the same seed ,the same sequence. So I got mass common rand number.But when I change it as time.Now().UnixNano(), the seed will not be the same because of the unixnano. so I got correctly. thank you very much
在 2019年6月27日星期四 UTC+8上午10:52:56,Burak Serdar写道: