Skip to content

Commit

Permalink
调整:随机数
Browse files Browse the repository at this point in the history
  • Loading branch information
steden committed Jul 16, 2024
1 parent 6db8cf6 commit df8ddea
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions serverVO.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/farseer-go/fs/trace"
"github.com/farseer-go/utils/http"
"math/rand"
"time"
)

const tokenName = "FSchedule-ACCESS-TOKEN"
Expand All @@ -31,10 +32,10 @@ func (receiver *serverVO) getAddress(ignoreIndex int) (serverAddress, serverInde
return receiver.Address[0], 0
}

index := rand.Intn(count - 1)
index := rand.New(rand.NewSource(time.Now().UnixNano())).Intn(count - 1)
// 如果随机到的索引值与要排除的索引值一样时,则重新随机
for ignoreIndex == index {
index = rand.Intn(count - 1)
index = rand.New(rand.NewSource(time.Now().UnixNano())).Intn(count - 1)
}
return receiver.Address[index], index
}
Expand Down

0 comments on commit df8ddea

Please sign in to comment.