1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-29 23:36:25 -04:00

simplify random

This commit is contained in:
Darien Raymond 2016-11-18 21:34:42 +01:00
parent a14795e1e6
commit 1a1383c2ea
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -41,15 +41,16 @@ func NewUDPPayloadQueue(option ListenOption) *UDPPayloadQueue {
func (this *UDPPayloadQueue) Enqueue(payload UDPPayload) {
size := len(this.queue)
idx := 0
if size > 1 {
idx = dice.Roll(size)
}
for i := 0; i < size; i++ {
idx := 0
if size > 1 {
idx = dice.Roll(size)
}
select {
case this.queue[idx] <- payload:
case this.queue[idx%size] <- payload:
return
default:
idx++
}
}
}